Please bear with me as I am noob in WCF services/ Windows services. I've created a WCF service hosted in a Windows service. I want to consume WCF service in a Silverlight in-browser application. Below is the code fragment in Silverlight to access WCF service:
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);
private void AddCallback(IAsyncResult asyncResult)
{
try
{
double endAdd = ((ICalcService) asyncResult.AsyncState).EndAdd(asyncResult);
}
catch (Exception exception)
{
throw exception;
}
}
I could consume the WCF service without any exception in other local non-silverlight application. But in Silverlight, it throws the exception System.ServiceModel.CommunicationException with following message:
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.
The innerException of type System.Net.Sockets.SocketException says
An attempt was made to access a socket in a way forbidden by its access permissions.
Googling around suggested me a solutions like disabling firewall, adding following tags in ClientAccessPolicy.xml :
<grant-to>
<socket-resource port="4502-4534" protocol="tcp" />
</grant-to>
Unfortunately none of the solutions helped me. I suppose this problem is relating to ClientAccessPolicy.xml. I suspect I am missing to put ClientAccessPolicy.xml at right location. I've kept it at the root of the WCF service. Will that work for netTcpBinding? If ClientAccessPolicy.xml is not the culprit, what may be the cause behind this exception?