C# 使用WCF服务的Silverlight客户端

C# 使用WCF服务的Silverlight客户端,c#,wcf,silverlight,nettcpbinding,clientaccesspolicy.xml,C#,Wcf,Silverlight,Nettcpbinding,Clientaccesspolicy.xml,请容忍我,因为我是WCF服务/Windows服务的新手。我已经在Windows服务中创建了一个WCF服务。我想通过TCP在Silverlight浏览器应用程序中使用该WCF服务。下面是Silverlight中访问WCF服务的代码片段: var messageEncoding = new BinaryMessageEncodingBindingElement(); var tcpTransport = new TcpTransportBindingElement()

请容忍我,因为我是WCF服务/Windows服务的新手。我已经在Windows服务中创建了一个WCF服务。我想通过TCP在Silverlight浏览器应用程序中使用该WCF服务。下面是Silverlight中访问WCF服务的代码片段:

        var messageEncoding = new BinaryMessageEncodingBindingElement();
        var tcpTransport = new TcpTransportBindingElement();
        var binding = new CustomBinding(messageEncoding, tcpTransport);

        // Create a channel factory for the service endpoint configured with the custom binding.
        var cf = new ChannelFactory<ICalcService>(binding, new EndpointAddress("net.tcp://192.168.2.104:4508"));

        // Open the channel.
        ICalcService channel = cf.CreateChannel();

        // Invoke the method asynchronously.
        channel.BeginAdd(9, 5, AddCallback, channel);
代码有时工作正常,但由于某些原因,它经常抛出臭名昭著的System.ServiceModel.CommunicationException,并显示以下消息:

Could not connect to net.tcp://192.168.2.104:4508/. The connection attempt lasted for a time span of 00:00:00.1010058. TCP error code 10013: An attempt was made to access a socket in a way forbidden by its access permissions.. This could be due to attempting to access a service in a cross-domain way while the service is not configured for cross-domain access. You may need to contact the owner of the service to expose a sockets cross-domain policy over HTTP and host the service in the allowed sockets port range 4502-4534.
类型为System.Net.Sockets.SocketException的innerException表示

An attempt was made to access a socket in a way forbidden by its access permissions.

这种例外情况背后可能的原因是什么?根据我到目前为止的调查,我只能找到一个原因:ClientAccessPolicy.xml不正确。其他原因可能是什么?如果你有任何有用的资源,请提供给我相同的。还有一个问题,如果我想让Windows服务托管的WCF服务被局域网上的其他机器使用,我需要做什么设置?例如防火墙设置?我的代码无法访问其他计算机上的WCF服务。它抛出与我上面提到的相同的异常。有没有关于如何消除此异常的想法?

问题已排序。。!!我必须做以下事情:

1) 在Windows服务中创建
NetTcpBinding
时指定了
SecurityMode.None


2) 在具有高级安全性的Windows防火墙中创建了入站规则,以允许在端点地址中指定的端口上进行TCP通信。

此链接除外:我无法帮助您解决此错误,但应将防火墙配置为允许Windows服务可执行文件的传入请求,或者,如果您不打算更改服务端口,请允许在该端口上传入tcp流量请求。谢谢您的建议@Andreas。。!!
An attempt was made to access a socket in a way forbidden by its access permissions.