none
Access a socket in a way forbidden by its access permissions

    General discussion

  • Hi,

    I have a Silverlight Web Application that needs to communicate with my server application for sending 
    data through TCP Sockets. Each time try to connect I am getting an Access Denied SocketError message.

    [http://localhost:50265/]

    1- Silverlight 5 + .net framework 4 and Windows 7 pro + Visual Studio 2010

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

    ClientAccessPolicy.xml:
    <?xml version="1.0" encoding ="utf-8"?>
    <access-policy>
    <cross-domain-access>
    <policy>
    <allow-from>
    <domain uri="*"/>
    </allow-from>
    <grant-to>
    <socket-resource port="4502-4506" protocol="tcp" />
    </grant-to>
    </policy>
    </cross-domain-access>
    </access-policy>
    Silverlight MainPage Code:
    void OnLoaded(object sender, RoutedEventArgs e)
    {
    buffer = new byte[128];

    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
    ProtocolType.Tcp);

    SocketAsyncEventArgs args = new SocketAsyncEventArgs()
    {
    SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http,
    RemoteEndPoint = new DnsEndPoint("localhost", 4502),
    };

    args.Completed += (s, eventArgs) =>
    {
    if (eventArgs.SocketError == SocketError.Success)
    {
    this.connectedSocket = socket;
    BeginRead();
    }
    };

    socket.ConnectAsync(args);
    }
    Please advise how to resolve this issue? 

    Thanks
    http://www.prepareuktest.co.uk/ 
    Thursday, January 12, 2012 11:30 AM