1)I create one WCF Service Appliaction as WCFServiceForStream.
2)My IService1,cs contains,
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Data;
using System.IO;
namespace WCFServiceForStream
{
[ServiceContract]
public interface IService1
{
[OperationContract]
Stream GetStream();
}
}
3)My Service1.svc as,
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Data;
namespace WCFServiceForStream
{
public class Service1 : IService1
{
public Stream GetStream()
{
//this file path assumes the image is in
// the Service folder and the service is executing
// in service/bin
string filePath = Path.Combine(System.Environment.CurrentDirectory,".\\..\\image.jpg");
//open the file, this could throw an exception
//(e.g. if the file is not found)
//having includeExceptionDetailInFaults="True" in config
// would cause this exception to be returned to the client
try
{
FileStream imageFile = File.OpenRead(filePath);
return imageFile;
}
catch (IOException ex)
{
Console.WriteLine(
String.Format("An exception was thrown while trying to open file {0}", filePath));
Console.WriteLine("Exception is: ");
Console.WriteLine(ex.ToString());
throw ex;
}
}
}
}
4)My web.config as,
="1.0"
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="basicConfig">
<binaryMessageEncoding/>
<httpTransport transferMode="Streamed" maxReceivedMessageSize="67108864"/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
But when I run Service1.svc for Hosting,
It will give me error as,
this operation is not supported in the wcf test client because it uses type system.io.stream
even if method returns stream.