简体   繁体   English

Byte[]/stream 通过 namedPipe WCF 出错

[英]Byte[]/stream through namedPipe WCF is faulted

I am developping a namedpipe Duplex WCF service.我正在开发一个 namedpipe Duplex WCF 服务。

For the basic things, the client and the server are communicating without issue.对于基本的事情,客户端和服务器可以毫无问题地进行通信。 The server can callback the client sending him strings, and it does it without any issue.服务器可以回调客户端向他发送字符串,并且它没有任何问题。 But, when i want it to send a bitmap with byte[] or stream, everything is faulting.但是,当我希望它发送带有字节 [] 或流的位图时,一切都出错了。 Just note i tried to use the stream because the byte[] is not working... In server side, the byte[]/stream is generated without issue.请注意,我尝试使用流,因为字节 [] 不起作用......在服务器端,字节 []/流的生成没有问题。 But when the server sends the byte[]/stream to the client,if the byte[]/stream is empty it goes through but when it has data it is faulting.但是当服务器将字节[]/流发送给客户端时,如果字节[]/流为空,它会通过,但是当它有数据时,它就会出错。

I already checked all my configurations, and tried to set a large buffer/message/poolsize/stringcontent/arraylenght/byteperread/whatever size/lenght because i know that's a classic issue in WCF.我已经检查了我的所有配置,并尝试设置一个大缓冲区/消息/池大小/字符串内容/arraylenght/byteperread/任何大小/长度,因为我知道这是 WCF 中的一个经典问题。

Here is a C/P of the main part of my WCF Config file.这是我的 WCF 配置文件主要部分的 C/P。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <netNamedPipeBinding>
        <binding name="NamedPipeBinding_ICameraService" closeTimeout="00:05:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" maxConnections="10" maxBufferPoolSize="500000000" maxBufferSize="500000000" maxReceivedMessageSize="500000000">
          <readerQuotas maxDepth="32" maxStringContentLength="500000000" maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000"/>
          <security mode="Transport"/>
        </binding>
      </netNamedPipeBinding>
    </bindings>
    <services>
      <service name="EOSDigital.CameraService" behaviorConfiguration="MEX">
        <endpoint address="net.pipe://localhost/EOSDigital/CameraService" binding="netNamedPipeBinding" bindingConfiguration="NamedPipeBinding_ICameraService" contract="EOSDigital.ICameraService"/>

        <endpoint address="net.pipe://localhost/EOSDigital/CameraService/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MEX">
          <serviceMetadata httpGetEnabled="False"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Here is the service callback contract这是服务回调合约

[ServiceContract]
public interface ICameraServiceCallBack
{
    [OperationContract(IsOneWay = true)]
    void CallBackFunction(string str);

    [OperationContract(IsOneWay = true)]
    void LiveviewUpdated(byte[] img);
}

And here is the declaration of my Service contract.这是我的服务合同的声明。

[ServiceContract(CallbackContract = typeof(ICameraServiceCallBack))]
public interface ICameraService

I wont put everything, this is too huge.我不会把所有东西都放进去,这太大了。

This is how i use it这就是我如何使用它

private void CurrentCamera_LiveViewUpdated(object sender, Stream img)
{
    MemoryStream data = new MemoryStream();
    img.CopyTo(data);

    _callback = OperationContext.Current.GetCallbackChannel<ICameraServiceCallBack>();

    _callback.CallBackFunction("this is a test"); // ok

    _callback.LiveviewUpdated(data.ToArray()); //Faulted
}

I get the Stream from a Canon digital Camera and it is around byte[146242].我从佳能数码相机获取流,它大约是字节 [146242]。 When i send a byte[10] it works.当我发送一个字节 [10] 时,它可以工作。 It has to be a problem of size, and I guess i missed something in the config file ...它必须是大小的问题,我想我在配置文件中遗漏了一些东西......

I also tried to generate and take a look to the scvclog file of my service to see some details of the occurring faulted exception.我还尝试生成并查看我的服务的 scvclog 文件,以查看发生的错误异常的一些详细信息。 But, well... There is not less than 50k characters in one line.但是,嗯……一行不少于 50k 个字符。 This is not readable.这是不可读的。

Thank you.谢谢你。

Check your client WCF configuration.检查您的客户端 WCF 配置。 Your client configuration must have the same netNamedPipeBinding as your host.您的客户端配置必须与您的主机具有相同的 netNamedPipeBinding。

Put that in your client config file把它放在你的客户端配置文件中

<netNamedPipeBinding>
  <binding name ="duplexEndpoint" closeTimeout="00:05:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="50000000" maxBufferSize="50000000" maxConnections="10" maxReceivedMessageSize="50000000">
    <readerQuotas maxDepth="32" maxStringContentLength="50000000" maxArrayLength="50000000" maxBytesPerRead="50000000" maxNameTableCharCount="50000000"/>
  </binding>
</netNamedPipeBinding>

This have to be put bellow the serviceModel.Bindings bracket.这必须放在 serviceModel.Bindings 括号下面。

Then, bind the configuration in your endpoint bracket然后,将配置绑定在您的端点支架中

bindingConfiguration="duplexEndpoint" 

That should do what you expected.那应该做你所期望的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM