locked
Not able to connect to a self hosted WCF service from a metro style app

    Question

  • I am hosting a WCF service in a Windows Forms desktop application and trying to access this service from a Metro style application on the same machine.

    First I had to change the endpoint binding from wsHttpBinding to basicHttpBinding, because WinRT does not support it. Then I was able to add a reference to my service to the metro app.

    Then I got the exception

    A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.ServiceModel.dll

    Additional information: The type 'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior, Microsoft.VisualStudio.Diagnostics.ServiceModelSink, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' registered for extension 'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior' could not be loaded.

    By turning WCF diagnostics off via vsdiag_regwcf.exe -u I was able to call into my service without getting the above exception.

    But after a while, I am getting a timeout exception from the call.

    I have tested the service with a desktop client application and that works fine.

    The address of my service is http://localhost:8080/MyService. Is there anything else that I have to configure for this scenario to work?

    I tried to connect to the Bing maps search service successfully from my metro app, so in principal the access to services works.

    Best regards,

    Bernd

     

     

     

     

     

     

     

    Thursday, September 22, 2011 9:25 PM

Answers

  • Hi Bernd,

    Metro apps currently block localhost traffic unless the service is also hosted in the same process - http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/17a542e1-8035-4139-9395-d73e3b222eb6. I agree that this is quite a limitation and we are working to see how best to address this. There are a few options for you:

    1) There is a command line tool described at the link above - CheckNetIsolation.exe - you can use that to remove this limitation.

    2) Host the service cross machine.

    3) Host the service on a vm on the win8 machine.

    You can see my blog post here - http://blogs.msdn.com/b/piyushjo/archive/2011/09/22/wcf-in-win8-metro-styled-apps-absolutely-supported.aspx about the differences of creating a wcf client b/w a classic desktop and a metro app.

     


    - Piyush
    • Marked as answer by RAB36 Friday, September 23, 2011 9:41 PM
    Friday, September 23, 2011 5:35 AM
  • Hi Piyush,

    thank you for the quick answer.

    I added my application to the loopback exempt list using

    checknetisolation loopbackexempt -a -n=[Package Family Name]

    (alternatively you can more simply add the Home/work networking capability), but it still did not work.

    The solution was, that I had to configure the Windows firewall despite the fact, that server and client app are running on the same machine.

    Any metro style app is "remote" for Windows and therefore the firewall comes into play.

    When I added the port of my service address as a port rule for TCP, it worked.

    Best regards,

    Bernd

     


    • Edited by RAB36 Friday, September 23, 2011 9:41 PM Firewall configuration is to be expected. Problem solved.
    • Marked as answer by RAB36 Friday, September 23, 2011 9:41 PM
    Friday, September 23, 2011 8:27 PM

All replies

  • Hi Bernd,

    Metro apps currently block localhost traffic unless the service is also hosted in the same process - http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/17a542e1-8035-4139-9395-d73e3b222eb6. I agree that this is quite a limitation and we are working to see how best to address this. There are a few options for you:

    1) There is a command line tool described at the link above - CheckNetIsolation.exe - you can use that to remove this limitation.

    2) Host the service cross machine.

    3) Host the service on a vm on the win8 machine.

    You can see my blog post here - http://blogs.msdn.com/b/piyushjo/archive/2011/09/22/wcf-in-win8-metro-styled-apps-absolutely-supported.aspx about the differences of creating a wcf client b/w a classic desktop and a metro app.

     


    - Piyush
    • Marked as answer by RAB36 Friday, September 23, 2011 9:41 PM
    Friday, September 23, 2011 5:35 AM
  • Hi Piyush,

    thank you for the quick answer.

    I added my application to the loopback exempt list using

    checknetisolation loopbackexempt -a -n=[Package Family Name]

    (alternatively you can more simply add the Home/work networking capability), but it still did not work.

    The solution was, that I had to configure the Windows firewall despite the fact, that server and client app are running on the same machine.

    Any metro style app is "remote" for Windows and therefore the firewall comes into play.

    When I added the port of my service address as a port rule for TCP, it worked.

    Best regards,

    Bernd

     


    • Edited by RAB36 Friday, September 23, 2011 9:41 PM Firewall configuration is to be expected. Problem solved.
    • Marked as answer by RAB36 Friday, September 23, 2011 9:41 PM
    Friday, September 23, 2011 8:27 PM
  • Hi Piyush,

    Does Microsoft plan to ease the Network Isolation (NS) localhost restriction for WCF service hosting in a different process for Win8 Metro?  The current NSrestriction disables a widely needed application architecture model which is a short sighted solution to address a security concern.  A central local services authentication and authorization mechanism would address both problems of allowing legit local service to run, while secure the system from malware.

    Thx,

     

     

     


    Coder
    Thursday, October 20, 2011 8:36 PM
  • Hi,

    We are having discussions to make it easy for local development/debugging scenario. Do you have scenarios where you would eventually production deploy the WCF service locally also such that both metro client and WCF service are on the same machine? Thanks.


    - Piyush
    Saturday, October 22, 2011 12:25 AM
  • <Removed>

    • Edited by fsleeper Thursday, March 29, 2012 8:26 PM
    Monday, October 31, 2011 11:07 PM
  • Piyush,

    Ofcourse there are! What do you think about connecting to a (local) database. For metro style apps, its not possible to directly connect to a database. Therefore, you need to create an extra webservice layer. Now, it's even impossible to do that, because local webservices are blocked. To be able to use Metro Style apps, you first need an extra server machine to connect to. Otherwise your metro style app on your tablet is worthless. Doesn't this sound ridiculous?

    Sunday, January 22, 2012 12:45 PM
  • A scenario where the WCF service and metro client are on the same machine (a desktop) is where the WCF service controls some equipment. Why have to write a desktop client to run on the machine running the WCF service and a metro client to run on a tablet or other mobile device? Why not just one metro client that can be run both locally and remotely with the ability to restrict access to only a local client when appropriate?
    Monday, January 23, 2012 2:26 PM
  • Hi PiyushJo

    discussion of newer builds deleted

    This forum is exclusively for discussion of the public Windows Developer Preview. If you have a later build under NDA please address any questions through the channel from which you received it.

    Wednesday, February 8, 2012 11:08 PM
  • Hi Piyush,

    thank you for the quick answer.

    I added my application to the loopback exempt list using

    checknetisolation loopbackexempt -a -n=[Package Family Name]

    (alternatively you can more simply add the Home/work networking capability), but it still did not work.

    The solution was, that I had to configure the Windows firewall despite the fact, that server and client app are running on the same machine.

    Any metro style app is "remote" for Windows and therefore the firewall comes into play.

    When I added the port of my service address as a port rule for TCP, it worked.

    Best regards,

    Bernd

     


          Hi Bernd,

          What do you mean by saying "When I added the port of my service address as a port rule for TCP, it worked."

          You config firewall ? Why I can not find any port rule settngs ?

          Can you describe that in more detail? 

          Thanks

    Monday, July 16, 2012 4:33 AM
  • Hi xiangangzhi,

    yes, actually I configured the firewall by adding a rule for the TCP port number I was using in my service. This was with Win 8 developer preview. I do not know whether something has changed in the firewall UI since then.

    Regards,
    Bernd

    Monday, July 16, 2012 6:48 AM