为网络启用共享时Metro风格应用程序中的套接字异常

时间:2012-07-10 19:56:37

标签: web-services windows-8 microsoft-metro windows-runtime

我正在开发一种Metro风格的应用程序,它通过Web服务与我们的服务器通信。早期,我发现我需要在清单中添加“家庭或工作网络”(privateNetworkClientServer)和“Internet客户端”(internetClient)功能,否则应用程序在尝试向远程进行Web服务调用时会遇到异常主机。

但是,现在,在某些计算机上,当应用程序尝试调用我们的Web服务时,我收到以下套接字异常:

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()

有趣的是,如果我禁用共享(右键单击wifi连接,选择“打开或关闭共享”,然后选择“否,不要打开共享或连接到设备”),问题就会消失Web服务调用成功。如果然后返回并重新开启共享(选择“是”而不是“否”),问题将返回。

因此,问题似乎与网络是否已启用共享和设备有关。我不完全确定映射,但我认为这基本上归结为“家庭/工作”和“公共”网络之间的区别;在我的情况下,当网络是“家庭/工作”时,Web服务调用失败,当网络是“公共”时,Web服务调用成功 - 但我的应用程序声明了两种类型的网络功能,并且所有框都不会出现此问题。也没有防火墙或其他网络限制;这是一个简单的Win8安装,没有额外的调整。

最后,这不是孤立于Web服务的 - 同一个应用程序的iframe在Web服务的某些条件下失败或成功。

2 个答案:

答案 0 :(得分:6)

我确实遇到了同样的问题。我通过在Package.appxmanifest文件中设置正确的功能解决了这个问题。在那里你必须检查互联网(客户端)和专用网络(客户端和服务器)。

这适用于VS 2012和Windows RT。

答案 1 :(得分:2)

检查专用网络是否配置为功能...如果网络连接配置为工作/主页,则需要此功能