Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket exception in Metro-style app when sharing is turned on for a network

I'm working on a Metro-style app that communicates with our server via a web service. Early on, I discovered that I needed to add the "Home or Work Networking" (privateNetworkClientServer) and "Internet Client" (internetClient) capabilities in the manifest, or else the app would hit exceptions when attempting to make web service calls to a remote host.

Now, however, on some machines I'm getting the following socket exception when the app tries to call our web service:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at https://[my_service_url] that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: Unable to connect to the remote server
---> 
System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions [my_server_ip_address]:443
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStreamAsyncResult.CompleteGetRequestStream(IAsyncResult result)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass5`1.<CreateGenericTask>b__4(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Interestingly enough, if I disable sharing (right-click the wifi connection, select "Turn sharing on or off", and choose "No, don't turn on sharing or connect to devices"), the problem goes away and web service calls succeed. If then go back and turn sharing back on (select "yes" instead of "no"), the problem returns.

So it appears that the problem is related to whether the network has sharing and devices enabled. I'm not completely sure of the mapping, but I think this basically boils down to the distinction between "home/work" and "public" networks; in my case the web service calls fail when the network is "home/work" and succeed when the network is "public" - but my app has both types of networking capabilities declared, and this issue doesn't occur on all boxes. There is also no firewall or other networking restriction in place; it's a bare-bones Win8 install with no additional tweaking.

Finally, this isn't isolated to web services - the same app has iframes that fail or succeed under the exact some conditions as the web services.

like image 977
atkretsch Avatar asked Jul 10 '12 19:07

atkretsch


2 Answers

I did have the same problem. I solved the problem by setting the right capabilities in the Package.appxmanifest file. There you have to check Internet (Client) and Private Networks (Client & Server).

This works for me on VS 2012 and Windows RT.

like image 175
Rod Avatar answered Nov 10 '22 01:11

Rod


Check if Private Network is configured as a capability... If the network connection is configured as either Work/Home it will require this capability

like image 24
ClementM Avatar answered Nov 10 '22 00:11

ClementM