rfuller123

Whenever I try to connect using a System.Net.Socket inside an xbap I get a 'System.Security.SecurityException'. Aren't sockets supposed to work inside xbaps as long as they're connecting back to the same host they were served from. For testing purposes I'm running a socket server on the same machine I'm developing the xbap on, and the xbap is still unable to connect without throwing a security exception. Can anyone help me get sockets working inside xbaps Thanks for any help you can provide.

The exception I'm getting is System.Security.SecurityException
Request for the permission of type 'System.Net.SocketPermission, ... failed.'

My code is simple:

Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress serverAddress = IPAddress.Parse("127.0.0.1");
int portNumber = 8000;
IPEndPoint serverEndPoint = new IPEndPoint(serverAddress, portNumber);
mySocket.Connect(serverEndPoint);

-rfuller


Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

Drew Marsh

Uhh, I don't think you're allowed to use raw sockets, no. You can use HttpWebRequest and only back to the site of origin (i.e. same domain name).

Later,

Drew





Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

rfuller123

Well thats no good. That means xbap games are out of the question. Why would sockets be disallowed

-rfuller




Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

Tamir Khason

You are right, this not allowed, however in debug mode sandbox. You can use ClickOnce for deployment in FullTrust mode. Then you can use sockets.

Here good blog post for trusted deployment http://blogs.msdn.com/karstenj/archive/2005/11/29/498061.aspx






Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

rfuller123

The post says that a trusted site cert has to be installed on the user's machine, but doesn't say how a trusted site cert can be deployed to the user's machine over the web. If the user has to download an installer to use my app that defeats the whole purpose of using an xbap. Are xbaps really that crippled that they can only run applications that don't actually do anything

-rfuller




Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

ivolved_Mike_Brown

By games do you mean action or timing based games Or do you mean board/turn based games A turn based game is definitely possible using just web services. You might have to make your clients poll the server for changes to game state, but it's definitely possible.






Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

rfuller123

Are there any third party socket libraries that would work in an xbap and not be subject to these restrictions

-rfuller123




Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

Kudzu22

No, the library wont matter. Its a CAS restriction. Any other socket set would need to use SNS, or PInvoke. Both of which are not allowed in XBAP.

HTTP connections can be held open. I havent looked deeply how the restriction is on webservices. I know XBAPs are allowed to make connections back to the same domain. Possibly it is not limited to web services, but HTTP connections and you could HTTP tunnel so long as the domain restriction is met.





Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

rfuller123

Sounds like a persistent http connection may be my only hope of getting this to work. Do you have any information on implementing something like this in .net Thanks for any further info you can provide.

-rfuller




Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

rfuller123

I can't seem to find any way to use a System.Net.WebRequest or System.Net.HttpWebRequest object to create a persistent http connection. On the WebRequest object I can call GetResponse() once and get a response, but subsequent calls never produce any results, even if the server has written more data to the stream. That could be part of the problem however. I'm using the HttpListener class as my server and to write to the response stream I actually have to call stream.close(). Calling flush doesn't do anything.

StreamWriter writer = new StreamWriter(httpListenerContext.Response.OutputStream);
writer.Write("my text");
writer.Flush(); //doesn't seem to do anything, doesn't send the data.
writer.Close(); //this sends the data, but the stream doesn't seem usable after.

Can anyone help

-rfuller





Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

Drew Marsh

There's no such thing... HTTP is a request/response protocol. Persistent connections refer to keeping the TCP/IP connection open. Each HTTP request is still one request == one response.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

rfuller123

So how then do I http tunnel to get tcp socket-like behavior inside an xbap I need a connection where the server can send info to the client. I need bi-directional communication inside an xbap. Is this possible

-rfuller




Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

Drew Marsh

No, it is not possible with the with the HTTP protocol. As a previous poster stated, you would have to poll for game state changes. The only solution if you want to use Sockets is to request elevated permissions from your XBAP.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

damy

as far as I can see now, both xbap and silverlight are missing any socket support. Here flash/flex have a big advantage when you want to create games or real-time apps with pushing from the server. Sometimes polling is just not what you want.




Re: Windows Presentation Foundation (WPF) Using sockets inside xbaps causes security exception

Drew Marsh

It's just the way the sandbox works. It's not that you can't use sockets at all from XBAP, it's just that you have to ask the user for permission to. I wasn't aware that Flash allowed socket communication out-of-the-box and am surprised to find that it does. I personally agree it should be allowed back to site-of-origin, but Microsoft would need to decide to lighten the default CAS policy for the Internet Zone to enable that.

Later,
Drew