wcf测试客户端不支持此操作,因为它在托管WCF服务时使用类型system.io.stream错误,即使方法返回流 [英] This operation is not supported in the wcf test client because it uses type system.io.stream error while hosting WCF service even if method return stream

查看:161
本文介绍了wcf测试客户端不支持此操作,因为它在托管WCF服务时使用类型system.io.stream错误,即使方法返回流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我创建一个WCF服务应用程序作为WCFServiceForStream。



2)我的IService1,cs包含,



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.ServiceModel;

使用System.Data;

使用System.IO;



名称空间WCFServiceForStream

{



[ServiceContract]

公共接口IService1

{

[OperationContract ]

流GetStream();

}

}



3)我的Service1.svc为,



使用System;

使用System.Collections.Generic;

使用System .Linq;

使用System.IO;

使用System.Data.SqlClient;

使用System.Data;



命名空间WCFServiceForStream

{

公共类服务1:IService1

{

public Stream GetStream()

{

//这个文件路径假定图像在
//服务文件夹并且服务正在执行

// in service / bin

string filePath = Path.Combine(System.Environment.CurrentDirectory,。\\....\\ image.jpg );

//打开文件,这可能会抛出异常

//(例如如果找不到该文件)

//在配置中包含includeExceptionDetailInFaults =True

//会导致此异常返回给客户端

尝试

{

FileStream imageFile = File.OpenRead(filePath);

返回imageFile;

}

catch(IOException ex)

{

Console.WriteLine(

String.Format(异常)在尝试打开文件{0},filePath)时抛出;

Console.WriteLine(例外是:);

Console.WriteLine(ex.ToString ());

抛出ex;

}

}



}

}



4)我的web.config为,

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,

<?xml version="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>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>











但是当我运行Service1.svc进行托管时,

它会给我错误,

wcf测试客户端不支持此操作,因为它使用类型system.io.stream

即使方法返回流。






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.

推荐答案

这是因为WCF测试客户端不支持 Stream 类型

MSDN [ ^ ]

This is because Stream type is not supported by WCF Test Client
MSDN[^]
The following is a list of features not supported by WCF Test Client:

    Types: Stream, Message, XmlElement, XmlAttribute, XmlNode, types that implement the IXmlSerializable interface, including the related XmlSchemaProviderAttribute attribute, and the XDocument and XElement types and the ADO.NET DataTable type.

    Duplex contract.

    Transaction.

    Security: CardSpace , Certificate, and Username/Password.

    Bindings: WSFederationbinding, any Context bindings and Https binding, WebHttpbinding (Json response message support).





希望,它有助于:)



Hope, it helps :)


这篇关于wcf测试客户端不支持此操作,因为它在托管WCF服务时使用类型system.io.stream错误,即使方法返回流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆