无法发送图像(byte [])作为WCF服务的参数

时间:2011-03-02 11:31:16

标签: wcf

我编写了一些服务,其中包含将image(byte [])作为参数的方法(返回void)。

我还写了一些客户端(客户端和服务器运行在相同的机器上 - 不同的闷 - 使用IIS)将位图(作为byte [])发送到服务 - 每次我尝试发送我得到异常:

收到http://localhost/WebService/Service.svc的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭)

我添加了另一个获取void并返回int的方法 - 我可以毫无问题地调用此方法。

有什么不对?我是否需要在客户服务参考中定义一些speciel?

服务方法

[ServiceContract]
**public interface IService**
{
    [OperationContract]
    void GetPic( byte[] pic );
}

**public class Service : IService**
{
    public void GetPic( byte[] pic )
    {
          ...   
    }
 }

Web.config文件:

 <system.serviceModel>
<services>
  <service behaviorConfiguration="ServiceBehavior" name="ServiceProxy.Service">

    <endpoint 
      name="basicHttp"
      address="" 
      binding="basicHttpBinding" 
      bindingConfiguration=""
      contract="Contracts.IService">
    </endpoint>

    <endpoint 
      address="mex" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" >
    </endpoint>

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8731/ServiceProxy/" />
      </baseAddresses>
    </host>

  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="True"/>       
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>

1 个答案:

答案 0 :(得分:3)

您必须在服务器上配置绑定以接受大邮件。默认情况下,它只接受最大65KB的消息和16k元素的数组=在你的情况下位图,其大小小于16KB。

在web.config(服务器端)中使用它:

<bindings>
  <basicHttpBinding>
    <binding name="myBinding" maxReceivedMessageSize="1000000">
      <readerQuotas maxArrayLength="1000000" />
    </binding>
  </basicHttpBinding>
</bindings>

在您的端点配置中,通过将其设置为bindingConfiguration,在myBinding属性中引用此绑定。