【发布时间】:2013-11-27 13:58:09
【问题描述】:
让我简单描述一下情况。
首先,我有一个使用这种方法的 WCF RestFul 网络服务:
[WebInvoke(UriTemplate = "/Dynamic/{*sParameter}", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
public string ExecuteWebAPIRequest(string sParameter, Stream streamPost)
{
...
var oClientFormatSinkProvider = new BinaryClientFormatterSinkProvider();
IDictionary aoProps = new Hashtable();
aoProps["port"] = 4626;
aoProps["timeout"] = "-1";
aoProps["name"] = "clientChan";
TcpClientChannel channel = new TcpClientChannel(aoProps, oClientFormatSinkProvider);
ChannelServices.RegisterChannel(channel, false);
//-- Call Bridge
string result = GetBridgeObject().ExecuteWebAPIRequest(sIpAddress, streamPost, sParameter);
//-- Return result
return result ?? "";
}
这是 GetBridgeObject() 方法的内容(即远程客户端):
private IBridge GetBridgeObject()
{
return (IBridge)Activator.GetObject(typeof(IBridge), "tcp://localhost:4626/RemoteBridge");
}
接下来是包含此方法的桥接进程(即远程服务器):
public void StartService()
{
//-- Initialize .NET remoting
var oServerFormatSinkProvider = new BinaryServerFormatterSinkProvider();
oServerFormatSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary aoProps = new Hashtable();
aoProps["port"] = 4626;
aoProps["timeout"] = "-1";
aoProps["name"] = "serverChan";
TcpServerChannel channel = new TcpServerChannel(aoProps, oServerFormatSinkProvider);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof (Bridge), "RemoteBridge", WellKnownObjectMode.Singleton);
}
最后,在远程桥对象中,这个方法:
public string WUPP_ExecuteWebAPIRequestI(string sPPInstanceName, Stream oInputStream, string sParameter)
{
...
int read = oInputStream.Read(buffer, 0, buffer.Length); //That's where the problem is
...
}
正如代码 sn-p 中所述,当我尝试读取流时出现问题,我收到此错误:
异常:System.Runtime.Remoting.RemotingException:此远程代理没有通道接收器,这意味着服务器没有注册的服务器通道正在侦听,或者此应用程序没有合适的客户端通道与服务器通信。 在 System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg,布尔值 useDispatchMessage,Int32 callType) 在 System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 类型) 在 System.IO.Stream.Read(Byte[] 缓冲区,Int32 偏移量,Int32 计数)
我确信我可以通过 .NET 远程处理传递流,因为在桥中,还有其他方法可以返回流并且效果很好。
注册频道时,我猜想问题出在远程服务器或客户端的某个地方,但经过两天的研究和测试,我仍然没有找到答案。
提前感谢您的帮助。
【问题讨论】:
标签: c# .net-4.0 stream remoting channel