While I try to use DataServiceCollection.loadAsync() to load data from a remote WCF data servcie, I always get an empty collection, like
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);
Then I checked the status with loadCompleted method and find that there is an error, like:
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)
I highly suspect that it is a problem caused by the server. But I can still use the browser to view the dataservice with the URL. Therefore, I checked the server side, the 8080 port is open, and I even added a clientaccesspolicy.xml to the root of the server project. the content:
<?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>
I closed the firewalls, but the client still cannot successfully load data. My Server is on Windows Server 2008 with SQL Server 2012. The same WCF Dataservices was deployed on a server running on Windows 7, and the client can successfully load data from it.
I do hope anyone can help me figure out the reason. Thx in advance.
BTW, same code runs smoothly in the console project.
According to your description, I think there is no IP contradiction or port occupation because the same code runs smoothly in your console project. You should check the .appxmanifest file of your Windows Store App, and make sure you have checked the Private Network (Clien & Server) in the capibilities tab.
The Private Network (Client & Server) capability provides inbound and outbound access to home and work networks through the firewall. This capability is typically used for games that communicate across the local area network (LAN), and for apps that share data across a variety of local devices.