Waleed Bin Khalid
Waleed Bin Khalid

Reputation: 3

Communication Exception in WCF via WP8

I have a simple WCF service deployed on localhost in IIS. I was able to access it from my windows phone app in the first. But after connecting to a different Wifi network at home I am unable to access it via new local IP. I have tried republishing the service. I also have tried reconfiguring the service reference in WP8 app. While adding the reference the add service wizard does detect the WCF service deployed on a new IP (The local IP address naturally changes after the laptop is connected to a different network). But whenever a simple Authenticate function is called from the device, it shows an exception. Stackoverflow would not let me post the screenshot because of low reputation, but the exact exception message is:

'An exception of type 'System.ServiceModel.CommunicationException' occured in System.ServiceModel.ni.dll but was not handled in user code' Additional Information: The remote server returned an error: NotFound.

This exception occurs in Reference.cs file over the second line of following function:

public string EndAuthenticateCustomer(System.IAsyncResult result) {
            object[] _args = new object[0];
            string _result = ((string)(base.EndInvoke("AuthenticateCustomer", _args, result)));
            return _result;
        }

I am running the app in debugging mode. If I run the installed app on my phone and try to access the service then it simply crashes. This is a part of my final year project. So I would be working in university as well as home which means the local IP on which the service is hosted will often change. I have looked for this exact problem over and over again with no luck. Any help would be appreciated.

Upvotes: 0

Views: 259

Answers (1)

Mark
Mark

Reputation: 8281

You would still have to provide the code where you instatiate the service, but you can configure the services IP when you instantiate it:

        // at home
        //const string ipAddress = "192.168.200.111";
        // at school
        const string ipAddress = "192.168.100.118";
        string address = string.Format("http://{0}/MobileService/DataService.svc", ipAddress);
        var mobileDataService = new MobileDataServiceClient(new MobileDataServiceClient.EndpointConfiguration(), new EndpointAddress(address));

You would have to change the IP depending on the network you are in. Alternatively you could push it to a server that has a constant IP e.g. Azure (if that is an option).

Upvotes: 1

Related Questions