首页 新闻 会员 周边

WCF Stream 出现"this operation is not supported

0
悬赏园豆:20 [已解决问题] 解决于 2010-07-24 18:22

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

奔跑*随心的主页 奔跑*随心 | 初学一级 | 园豆:140
提问于:2010-07-20 17:33
< >
分享
最佳答案
0

你看看你用wcf test工具生成配置文件中 transferMode 的值是什么?

没有估计错的话,应该是 transferMode = "Buffered"

另外,采用非IIS宿主的wcf服务,不支持streamed.

收获园豆:20
Launcher | 高人七级 |园豆:45045 | 2010-07-20 17:46
是streamed,上面的配置文件中有这句,另外我还没有发布服务,现在只是把服务程序运行起来
奔跑*随心 | 园豆:140 (初学一级) | 2010-07-20 17:49
@奔跑*随心: wcftestclient 不支持 Stream 为输入,输出参数,另外我再告诉你,wcftestclient还不支持callbackcontract.最后,还要告诉你,使用 wcftestclient 生成的配置文件中 transferMode="Buffered" 不是 Streamed,不是指你在服务端的配置,而是工具生成的客户端配置. 你为你的服务增加 [OperationContract] string GetData(int value); 该操作契约,你就可以在WcfTestClient中看到返回Stream的那个操作是红的,而返回string的是正常的.
Launcher | 园豆:45045 (高人七级) | 2010-07-21 09:13
@Galactica:谢谢 我试过了,虽然在WcfTestClient中看到返回Stream的那个操作是红的,但是我用IIS将WCF服务发布后,实际上是可以传的。
奔跑*随心 | 园豆:140 (初学一级) | 2010-07-24 18:29
其他回答(1)
0

大哥,是不是只有把WCF寄宿在IIS中,才能使用stream作为返回值,是吗?

其它的不行?

TimYang | 园豆:12 (初学一级) | 2013-08-05 12:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册