【发布时间】:2016-09-20 17:50:57
【问题描述】:
我正在开发一个命名管道 Duplex WCF 服务。
对于基本的事情,客户端和服务器通信没有问题。服务器可以回调客户端向他发送字符串,并且它没有任何问题。 但是,当我希望它发送带有字节 [] 或流的位图时,一切都出错了。请注意,我尝试使用流,因为 byte[] 不起作用... 在服务器端,byte[]/stream 生成没有问题。 但是当服务器向客户端发送字节[]/流时,如果字节[]/流为空,它会通过,但是当它有数据时,它就会出错。
我已经检查了我的所有配置,并尝试设置一个大的缓冲区/消息/池大小/字符串内容/arraylenght/byteperread/whatever size/lenght,因为我知道这是 WCF 中的一个经典问题。
这是我的 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>
这里是服务回调合约
[ServiceContract]
public interface ICameraServiceCallBack
{
[OperationContract(IsOneWay = true)]
void CallBackFunction(string str);
[OperationContract(IsOneWay = true)]
void LiveviewUpdated(byte[] img);
}
这是我的服务合同的声明。
[ServiceContract(CallbackContract = typeof(ICameraServiceCallBack))]
public interface ICameraService
我不会放所有东西,这太大了。
我就是这样用的
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
}
我从佳能数码相机获得流,它大约是字节 [146242]。当我发送一个字节 [10] 时,它可以工作。 这一定是大小的问题,我想我错过了配置文件中的某些内容...
我还尝试生成并查看我的服务的 scvclog 文件,以查看发生的错误异常的一些详细信息。 但是,好吧……一行不少于 50k 个字符。这是不可读的。
谢谢。
【问题讨论】:
标签: c# wcf named-pipes