This project is read-only.

ClientAccessPolicy not being searched for

Jun 27, 2012 at 7:49 PM
Edited Jun 27, 2012 at 7:51 PM

Hi Kerry,

So, having some really funky issues with a Silverlight attempt to use the WebSocket4Net framework.  I get the following issue (immediately) when attempting to connect to a remote host:

{System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions.}

There is no InnerException.  I had to go grab all of the SuperSocket.ClientEngine stuff to be able to debug lower, since it seems to be happening at the *lowest* possible level.

I set the option on the WebSocket (ClientAccessPolicyProtocol) to Http, as was suggested in another post on here.  Still no luck.  I don't see it even trying to find it through Fiddler...

Basically I have a server on which hosts a WebSocket (Microsoft one) and in WPF, the WebSocket4Net framework works PERFECTLY.  My computer is  I try to connect to ws:// which worked fine in WPF -- but this seems to have issues with Silverlight (again, not even downloading the ClientAccessPolicy...  no idea if it's trying to hit the Tcp Policy instead).  The WebSocket it's trying to connect to is not WCF, but a self-hosted WebSocket in a ConsoleApp.

I have no idea if I'm doing something wrong or if there is some error.

Here's my code:

            _socket = new WebSocket(Configuration.ServerUri, WebSocketSubscriptionConfiguration.SubProtocol, string.Empty);
            _socket.ClientAccessPolicyProtocol = System.Net.Sockets.SocketClientAccessPolicyProtocol.Http;
            _socket = new WebSocket(Configuration.ServerUri, WebSocketSubscriptionConfiguration.SubProtocol);

            _socket.DataReceived += (sender, e)
                    string unicodeMessage = Encoding.Unicode.GetString(e.Data);

                    WebSocketPayload payload = JsonConvert.DeserializeObject<WebSocketPayload>(unicodeMessage);


            _socket.Opened += (sender, e) =>
                    IsActive = true;

            _socket.Error += (sender, e) =>
                    catch (Exception)
                    { }
                        IsActive = false;

Jun 27, 2012 at 8:27 PM

OK, I feel *REALLY* dumb.  Apparently after I had made changes to my ClientAccessPolicy to allow for the TCP Ports, I forgot to clear Web Browser cache (though I thought I had) and it was using the old one.  The solution was to clear browser cache and it forced Silverlight to grab the ClientAccessPolicy again, this time, with the updated changes.

Jun 28, 2012 at 2:21 AM

Great, I am glad to know you have fixed it by yourself!