Windows store apps System.Net.Sockets.SocketException在使用商店应用程序连接到WCF数据服务时发生

Windows store apps System.Net.Sockets.SocketException在使用商店应用程序连接到WCF数据服务时发生,windows-store-apps,windows-server-2008,wcf-data-services,Windows Store Apps,Windows Server 2008,Wcf Data Services,当我尝试使用DataServiceCollection.loadAsync()从远程WCF数据服务加载数据时,我总是得到一个空集合,如 CloudEDUEntities ctx = new CloudEDUEntities(uri); DataServiceCollection<COURSE> dsc = new DataServiceCollection<COURSE>(); var query = from p in ctx.COURSEs s

当我尝试使用DataServiceCollection.loadAsync()从远程WCF数据服务加载数据时,我总是得到一个空集合,如

    CloudEDUEntities ctx = new CloudEDUEntities(uri);
    DataServiceCollection<COURSE> dsc = new DataServiceCollection<COURSE>();
    var query = from p in ctx.COURSEs select p;
    dsc.LoadAsync(query);//The count of dsc will always be 0
    dsc.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(complete);
cloudedutentities ctx=新的cloudedutentities(uri);
DataServiceCollection dsc=新的DataServiceCollection();
var query=从ctx中的p选择p;
LoadAsync(查询)//dsc的计数将始终为0
dsc.LoadCompleted+=新事件处理程序(完成);
然后我用loadCompleted方法检查了状态,发现有一个错误,如:

    System.InvalidOperationException: An error occurred while processing this request. ---> System.Data.Services.Http.WebException: Unable to connect to the remote server ---> 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 10.0.1.39:8080
       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.EndGetResponse(IAsyncResult asyncResult)
       at System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
       at System.Data.Services.Client.HttpWebRequestMessage.EndGetResponse(IAsyncResult asyncResult)
       at System.Data.Services.Client.ODataRequestMessageWrapper.EndGetResponse(IAsyncResult asyncResult)
       at System.Data.Services.Client.WebUtil.GetResponseHelper(ODataRequestMessageWrapper request, DataServiceContext context, IAsyncResult asyncResult, Boolean handleWebException)
       at System.Data.Services.Client.WebUtil.EndGetResponse(ODataRequestMessageWrapper request, IAsyncResult asyncResult, DataServiceContext context)
       at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
       at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
       at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)
       at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
       at System.Data.Services.Client.DataServiceCollection`1.<>c__DisplayClass2.<LoadAsync>b__1(IAsyncResult asyncResult)
       at System.Data.Services.Client.DataServiceCollection`1.EndLoadAsyncOperation(Func`2 endCall, IAsyncResult asyncResult)
System.InvalidOperationException:处理此请求时出错。-->System.Data.Services.Http.WebException:无法连接到远程服务器-->System.Net.WebException:无法连接到远程服务器-->System.Net.Sockets.SocketException:试图以访问权限10.0.1.39:8080禁止的方式访问套接字
位于System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
在System.Net.ServicePoint.ConnectSocketInternal(布尔连接失败、套接字s4、套接字s6、套接字和套接字、IPAddress和address、ConnectSocketState状态、IAsyncResult asyncResult、异常和异常)
---内部异常堆栈跟踪的结束---
位于System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
---内部异常堆栈跟踪的结束---
位于System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
位于System.Data.Services.Client.HttpWebRequestMessage.EndGetResponse(IAsyncResult asyncResult)
位于System.Data.Services.Client.ODataRequestMessageWrapper.EndGetResponse(IAsyncResult asyncResult)
位于System.Data.Services.Client.WebUtil.GetResponseHelper(ODataRequestMessageWrapper请求、DataServiceContext上下文、IAsyncResult asyncResult、Boolean handleWebException)
位于System.Data.Services.Client.WebUtil.EndGetResponse(ODataRequestMessageWrapper请求、IAsyncResult asyncResult、DataServiceContext上下文)
位于System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)
---内部异常堆栈跟踪的结束---
位于System.Data.Services.Client.BaseAsyncResult.EndExecute[T](对象源,字符串方法,IAsyncResult asyncResult)
在System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](对象源,字符串方法,IAsyncResult asyncResult)
在System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](对象源,DataServiceContext上下文,字符串方法,IAsyncResult asyncResult)
位于System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
在System.Data.Services.Client.DataServiceCollection`1.c__显示Class2.b__1(IAsyncResult asyncResult)
位于System.Data.Services.Client.DataServiceCollection`1.EndLoadAsyncOperation(Func`2 endCall,IAsyncResult asyncResult)
我高度怀疑这是由服务器引起的问题。但我仍然可以使用浏览器查看带有URL的数据服务。因此,我检查了服务器端,8080端口是开放的,我甚至向服务器项目的根添加了clientaccesspolicy.xml。内容:

    <?xml version="1.0" encoding="utf-8"?> 
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
        <socket-resource port="8080" protocol="tcp" />
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

我关闭了防火墙,但客户端仍然无法成功加载数据。我的服务器位于Windows Server 2008和SQL Server 2012上。 在运行Windows 7的服务器上部署了相同的WCF数据服务,客户端可以成功地从中加载数据

我真希望有人能帮我找出原因。Thx提前


顺便说一句,相同的代码在console项目中运行平稳

根据您的描述,我认为没有IP冲突或端口占用,因为相同的代码在console项目中运行平稳。您应该检查Windows应用商店应用程序的.appxmanifest文件,并确保已在功能选项卡中检查了专用网络(客户端和服务器)

专用网络(客户端和服务器)功能通过防火墙提供对家庭和工作网络的入站和出站访问。此功能通常用于通过局域网(LAN)进行通信的游戏,以及跨各种本地设备共享数据的应用程序


根据您的描述,我认为没有IP冲突或端口占用,因为相同的代码在您的console项目中运行顺利。您应该检查Windows应用商店应用程序的.appxmanifest文件,并确保已在功能选项卡中检查了专用网络(客户端和服务器)

专用网络(客户端和服务器)功能通过防火墙提供对家庭和工作网络的入站和出站访问。此功能通常用于通过局域网(LAN)进行通信的游戏,以及跨各种本地设备共享数据的应用程序