1

雖然我嘗試使用DataServiceCollection.loadAsync()從遠程WCF數據servcie加載數據,我總是得到一個空集,像System.Net.Sockets.SocketException同時連接到WCF數據服務與商店APP

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

然後我檢查與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) 

我高度懷疑這是造成服務器出現問題。但是我仍然可以使用瀏覽器通過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> 

我關閉了防火牆,但客戶仍無法成功加載數據。我的服務器位於帶有SQL Server 2012的Windows Server 2008上。 在Windows 7上運行的服務器上部署了相同的WCF Dataservices,並且客戶端可以成功從中加載數據。

我希望任何人都可以幫我找出原因。 Thx提前。

順便說一下,相同的代碼在控制檯項目平穩運行。

回答

1

根據您的描述,我認爲沒有IP矛盾或端口占用,因爲相同的代碼在您的控制檯項目中順利運行。您應該檢查Windows應用商店的.appxmanifest文件,並確保您已檢查資源選項卡中的專用網絡(Clien &服務器)

專用網絡(客戶端&服務器)功能通過防火牆提供對家庭和工作網絡的入站和出站訪問。此功能通常用於通過局域網(LAN)進行通信的遊戲,以及用於跨各種本地設備共享數據的應用程序。

You can get more information about capibilities here.