Search code examples
.netwcfwindows-phone-8wcf-binding

Windows Phone 8 Error with WCF - The remote server returned an error: NotFound


I'm not quite sure where to start!! This problem has been driving me crazy!

I'm trying to develop an app for Windows Phone 8 using WCF and while it use to work alright and I do say alright as every so often I was getting same communication error I'm getting now, it would eventually come back when I'd stop my network adapters and restart them, but I'd have to do this a few times.

Something happened, I still don't know what, but my emulator stop working altogether and it would just hang and I would get various errors. I uninstalled sdk 8, hyper-v a couple of times and I still was getting the error. I then uninstall the lot once again and deleted all hyper-v folder, config, etc... and while I'm not sure how I fixed it, it started to work when I swapped from Emulator WVGA 512MB to Emulator 720P. I then swapped back and somehow it started to work again... Doesn't make sense! I know!

Anyway, since my emulator is back up, I just haven't been able to get my app to communicate with my wcf service running from my desktop. I keep getting the following error:

{System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
    at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
    at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
    at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
    --- End of inner exception stack trace ---
    at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
    at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)}

So researched the error "The remote server returned an error: NotFound" and found numerous articles and pretty much tried everything that has been suggested, but still no luck!!

This is one specific article from Microsoft: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580%28v=vs.105%29.aspx

and while I haven't tried the IIS solution as I'm only starting to develop my wcf service, I've tried the IIS Express and nothing!! As I said earlier on this use to work!

The thing that drives me mad is that:

  1. I can access the .svc or via Http Activation in my web browser

  2. I can access my router's website in the emulator

  3. I can access the internet in the emulator

So it's definitely able to access and communicate with other devices but it just won't access my wcf service.

In another article I found (Don't have the link but will look for it later), it suggested to add a second binding in the applicationhost.config located in %userprofile%\Documents\IISExpress\config\ and when I did that I got an error which basically told me I wasn't allow to have 2 bindings unless I multipleSiteBindingsEnabled to true which I did and it solved that problem, but even after introducing the second binding using my full ip address instead of localhost and changing my service to use the .svc with the full ip address, again still no changes... Same error.

I don't believe I'm getting any errors as I've got a break point right at the beginning of my method and it doesn't get to execute any of the relevant code so it's fair (I think) to assume that's it not even getting there! I just don't understand why it use to work and now all of sudden it just stopped! Obviously related to my emulator giving me grief to begin with but still no resolution!!!

Has anyone got any suggestions? I'm at a complete stand still and have no idea where to go next!!! Extremely frustrating!


Solution

  • I figured out what the problem was!

    I'm so use to work on my own machine with a specific antivirus/firewall software but the machine I'm using is a test machine and it uses the standard windows firewall!!

    This was the problem!! Well, partially. Somehow, if I switch off the windows firewall service, it still won't let me connect but if I leave the firewall turned on and tell it not to monitor private networks, it worked immediately!

    I still don't know how it ever work in the first place as the firewall would have been on and so would have been the monitoring of private networks but somehow it is now working so I have to assume that this was the problem.

    Read this for more information on how to set this up depending on your scenario:

    http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580%28v=vs.105%29.aspx

    Personally, I decided to use a machine name instead of an IP as I constantly have new IP allocated to my machine depending on the network i'm connecting to but just added a specific port for a private and domain network, thus ensuring I can always access my wcf service.

    Hope this helps.