Answer Using web services with xbap application

  • Thursday, June 29, 2006 9:50 PM
     
     

    I have created an wpf browser application that relies on calling a web service.  However, whenever I call the web service, I recieve a "System.Net.WebPermissions" error message.  The web service is located on a different server.  How do I get this to work?   Thank you for the help.

     

    Steve

Answers

  • Thursday, June 29, 2006 10:07 PM
    Moderator
     
     Answer
    You cannot access a web service from a different server - it's because of the security restrictions.
    The only solution I can think of is to create a "proxy" - a web service on the same site that connects to the other web service. I have used this technique in one of my projects to connect to Amazon web services.
  • Saturday, July 01, 2006 8:47 PM
    Moderator
     
     Answer
    He means a proxy service on your web server which basically makes calls to the real web service. This technique is referred to as "bridging". If you download the Atlas CTP it has support for bridging built in. Check out this article on the Atlas site for more information. Keep in mind that just because it's Atlas doesn't necessarily mean you have to call it with Atlas client script.

All Replies

  • Thursday, June 29, 2006 10:07 PM
    Moderator
     
     Answer
    You cannot access a web service from a different server - it's because of the security restrictions.
    The only solution I can think of is to create a "proxy" - a web service on the same site that connects to the other web service. I have used this technique in one of my projects to connect to Amazon web services.
  • Saturday, July 01, 2006 3:03 AM
     
     

    Thank you for the suggestion.  I created a proxy class using the wsdl.exe (wsdl http://ri-webserv-1/service/service1.asmx?wsdl), compiled it into  a dll and then placed it inside the bin directory, and then referenced the code in the xbap document.  However, I still got the error.  Am I creating and/or consuming the proxy class correctly? 

     

    Steve

  • Saturday, July 01, 2006 8:47 PM
    Moderator
     
     Answer
    He means a proxy service on your web server which basically makes calls to the real web service. This technique is referred to as "bridging". If you download the Atlas CTP it has support for bridging built in. Check out this article on the Atlas site for more information. Keep in mind that just because it's Atlas doesn't necessarily mean you have to call it with Atlas client script.
  • Monday, July 03, 2006 6:22 PM
     
     

    Thank you for the help.  I am looking into this article and how to integrate with an wpf browser application.  "Bridging" seems to be what I need, and now I just have to determine how to bring it into the wpf world.

     

    Steve

  • Monday, July 10, 2006 7:32 PM
    Moderator
     
     

    It's simple, just use WCF in the WPF app. The fact that it's a bridge really has no bearing on the way you'll communicate with it. You're just pointing at the WCF client proxy to the bridge's URL on your server instead of the live service's URL.

    HTH,
    Drew

  • Monday, July 10, 2006 8:19 PM
     
     

    I just want to make sure I understand.  Your suggestion is to add to the browser application a wcf client and create a wcf service on the same server, and the wcf service does the bridging to the remote web services.  On the service side, I would add the calls to the web services that are hosted remotely as normal.  Assuming this is what you meant, I just need to clarify one other item.  Does the xbap consider the fact that the web service is on the same server, but different directory (i.e. the xbap is at http://localhost/xbapApp/bin/debug/XbapApp.xbap, and the service is located at http://localhost/webservice1/service1.svc) as being on the same server (site-of-origin) or does it calculate it differently?  Thank you again for your help.

     

    Steve

  • Monday, July 10, 2006 8:28 PM
    Moderator
     
     

    Yes, except you don't even need to use WCF on the server side, just use the Atlas bridging infrastructure (steps are documented here). It's 100% compatible with WCF on the client side.

    As for it being in a separate directory, that should not be a problem for the sandboxed environment. As long as you're talking to the same server, the directory has no bearing.

    HTH,
    Drew

  • Monday, July 10, 2006 10:37 PM
     
     

    I just wanted to make sure I am on the right track, since I am a little frustrated in trying to figure this out over the last week.    I do appreciate all the help.

     First, I created a sample atlas application and it worked well.  It was not that difficult to setup and use.  Now, when I want to use this with the xbap application, I just want to check on how to proceed.  Do I :  a)  Add a wcf reference and point it to the atlas application (and do I point it to the asmx or asbx file) or b) Add the microsoft.web.atlas.dll to the xbap, create the asmx and asbx file there, and then reference the asmx file or c) is there a better method? 

     

    Steve

  • Monday, July 10, 2006 10:52 PM
    Moderator
     
     
    I have never worked with Atlas but a) is not going to work because of the security restrictions - you cannot use WCF in XBAP. You can use plain web services (i.e. ASMX).
  • Monday, July 10, 2006 11:03 PM
    Moderator
     
     

    Well, the Atlas part is for the server so it's a non-issue there. It could be Java on the other side for all you care, makes no difference.

    Soooo.... admittedly I haven't looked at the sandbox restrictions for WCF. I just went and did some research based on your comment and sure enough it looks like partially trusted callers are not supported and WCF because support for CAS was dropped. Thank you for correcting me.

    This is really no big deal (like you said). It totally stinks that they don't support it (unbelievable actually), but for this scenario you can just use the basic .NET framework support for client proxies. Just generate the proxy using wsdl.exe or by adding a Web Service Reference in the IDE.

    Cheers,
    Drew

  • Monday, July 10, 2006 11:14 PM
     
     

    If wcf would not work, and I am getting an web.permissions error even with local asmx web services (same computer, different application directories:  the xbap at http://steveppc/tstpub/tstXBAPJuneCTP.xbap, and the asmx at http://steveppc/simplews/service.asmx).  I can get away with this if I turn it into a full trust application, but then I do not know how to deploy such an xbap (everytime I publish, I receive a can't install a full-trusted app).  That is what is frustating.

     

    Steve

  • Wednesday, August 16, 2006 9:13 AM
     
     

    I'm struggling with this too. I've created an xbap application, and an asmx web service, but I get the System.Net.WebPermission exception every time. Both the web service and the xbap are installed on the same IIS, different virtual directories (I'm not sure that it's possible to put them in the same directory?).

    Has anyone ever got an xbap application to connect to a database? Or even got this alleged web service mechanism to work at all? I'd be interested to hear from someone who has.

    Any help would be much appreciated.

  • Wednesday, August 16, 2006 10:22 AM
     
     

    Scratch that: it seems to be working now. Not sure what I did to fix it, but it's now working.

    Sorry to have troubled you if you read my previous post!

  • Wednesday, August 16, 2006 2:09 PM
     
     

    One strange bug in both the May and June CTP was the fact that an XBAP appplication that needed to call a web service would throw the permission error, but if you rebooted your machine, it actually works.  Hopefully this is fixed if they release an August CTP.  Good luck.

    Steve

  • Thursday, October 26, 2006 1:09 PM
     
     

    hai

       open project properties and in the security tab, give it full trust application. Your error will go.

  • Tuesday, November 28, 2006 2:05 PM
     
     

    I was use RC1, also have the ploblem. Only a changed to "Local Intranet" Permission, I can invoke the web Service successful.

    very puzzleed..

  • Friday, July 27, 2007 8:02 AM
     
     
    Hi buddies,

    There are some "cheat steps" that you should remember in order to deploy an XBAP application successfully (at least now)
    1. Access to database via a WebService (ASP.NET WebService, not WPF WebService)
    2. The WebService placed on the same host with the main site (may be in different folder)
    3. If you use Enterprise Library to access DB in your WebService, do not place the connection string in Application Config file; build the connection in memory:
    Database db = new SqlDatabase("your connection string")
    4. Remember to add "Trusted_Connection=True" to the connection string
    5. Increase the deployment revision every time publishing the XBAP (by default, this is done automatically). Do not roll back the revision
    6. The IIS must have an application running in the folder that contains your XBAP. Go to Properties page of the folder and choose to create a default application.
    7. Go to Security Tab and choose Full Trust app OR partial trust with Local Intranet option (OR choose Custom and customize your choices)
    8. Make sure your XBAP satisfies SandBox security.
    9. Finally, your SQLServer must have ASP.NET user install Smile Dont forget this

    An Pham
  • Thursday, August 09, 2007 6:28 PM
     
     

    Hi,

     

    I used Fully trusted mode and signed my XBAP application with a self created certificate. In this mode my XBAP application can talk to anything.

     

  • Thursday, August 09, 2007 10:59 PM
     
     

    Hi,

     

    It also works with asmx web services. You need to take care in this area when doing this.

     

    Service proxy generated url lets say: http://localhost/WeatherService.asmx

     

    Xbap deployed at local machine. you need to invoke the click once deployment only through http://localhost/Testapp.xbap

     

    if you try to invoke using http://127.0.0.1/Testapp.xbap or http://machinename/Testapp.xbap the call to webservice fails giving you  a security exception.

     

     

  • Friday, April 04, 2008 4:39 PM
     
     

     

    Can I ask you how you managed to get your WPF Browser to communicate with your web service?  Did you use anything else?  I have made a few different tests and I always have the same problem.  The application needs to be full trusted by Internet Explorer and even then it doesn’t work.  Did you add a certificate?

     

    Any help would be appreciated; I’m really bored to loose time on this.

     

    Thanks!

  • Tuesday, June 24, 2008 2:35 PM
     
     Proposed Answer
    Hy guys,

    I got this thing working. Here are the details:

    - First thing in advance: Check your computers full qualified domain name (FQDN). This is the most important thing in this whole issue.
    For example my computer has the computername pcdanielprivat. But if I look in the Workplace Details, there is "pcdanielprivat.detonator.local". Don't ever use "localhost" or "127.0.0.1". This will break your neck as soon as you want to distribute your application.

    - Use the FQDN also, when adding the WCF service reference to the xbap application. Otherwise, Visual Studio will use "localhost", which will screw you up again.

    - And last but not least - use the FQDN in the Publishing Folder location in the "Deploy" Panel of your xbap project. If you don't, the manifest will not contain the right domain name and you will not succeed at all.

    - With all the above settings, you will  be able to set your applications security level to "Internet" and everything will be fine.

    - To debug your xbap application follow the instructions from here : http://nirajrules.wordpress.com/2008/06/11/debugging-an-xbap-wcf-application-%E2%80%93-windows-vista-vsnet-2008/

    I've written an article about this issue on my homepage.

    Best regards

    Daniel


    • Proposed As Answer by kreuzhofer Tuesday, June 24, 2008 3:44 PM
    • Edited by kreuzhofer Tuesday, June 24, 2008 9:34 PM added link to my homepage with detailed information on this issue
    •