WCF服务类中有一个返回值类型为Stream的方法
[ServiceContract]
public interface IDMADBQueryServices
{
[OperationContract]
Stream GetTopic(string topicID);
}
借口实现为:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class DMADBQueryService:IDMADBQueryServices
{
public Stream GetTopic(string topicID)
{
return new MemoryStream();
}
}
配置文件为:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="bind1" maxReceivedMessageSize="90000000" transferMode="Streamed" />
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DMADBQueryServices.Service1Behavior"
name="DMADBQueryServices.DMADBQueryService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="bind1"
contract="DMADBQueryServices.IDMADBQueryServices" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/DMADBQueryServices/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DMADBQueryServices.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
现在运行服务,在WCF TEST工具中这个方法显示:
this operation is not supported in the wcf test because it use type system.io.stream
你看看你用wcf test工具生成配置文件中 transferMode 的值是什么?
没有估计错的话,应该是 transferMode = "Buffered"
另外,采用非IIS宿主的wcf服务,不支持streamed.
大哥,是不是只有把WCF寄宿在IIS中,才能使用stream作为返回值,是吗?
其它的不行?