I'm in the middle of trying to get my Silverlight application to communicate via sockets with my webserver but I'm having trouble connecting the Silverlight socket to the server.
This is the setup:
My webserver is set to listen to the 5432 port using a TcpListener on IPAddress.Any. I've got a clientaccesspolicy.xml accessable on localhost:943/clientaccesspolicy.xml looking like this:
Of course I've tried using the 'Application.Current.Host.Source.DnsSafeHost' instead of "localhost" since all tutorials and guides use it but I haven't been able to find any information about what exactly it contains, when I debug my silverapp. it's set to "" (empty string) which of course throws when inserted into the DnsEndPoint.
Finally worth mentioning is that I've checked the traffic using a sniffer and I cannot even catch the silverlight making any localhost requests so I suspect the problem lies in how I setup the DnsEndPoint (or some such).
Any help would be superb, I'm really at the end of my rope.
Re: SocketError.AccessDenied with Silverlight Sockets
Finally I've found a solution to this.
It seems Silverlight isn't designed to make it easy for you to use sockets and only after I tried setting up a custom made client access policy server the client would allow me to connect, thanks a lot to Dr. Dobb for this: http://www.ddj.com/windows/208403238
When using sockets Silverlight doesn't request the access policy file like it does when using web services (using http that is) but instead sends a neat little string <policy-file-request/> to the policy server which then needs to kindly send back the policy file. Well, well, problem solved at least.