Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Disable Cross-Domain restrictions on BrowserHttpWebRequ... RSS

20 replies

Last post Jun 19, 2007 01:22 AM by pkellner

(2)
  • gmcbay

    gmcbay

    Member

    6 Points

    6 Posts

    Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 05, 2007 05:06 AM | LINK

    I fully understand why there are cross-domain restrictions on BrowserHttpWebRequest calls, but is there any way to disable this for development, the way the Flash player allows users to override these restrictions for specific local SWFs or directories? 

    I'm trying to develop a Silverlight app that makes calls to a web server using these HttpWebRequests and while the Silverlight app will be deployed to the same web server that it makes these calls from, it would be dreadfully cumbersome to have to upload the built app there before testing it every single time I want to run it while developing it... Surely there must be some way to disable this security restriction for development purposes?

     

  • WilcoB

    WilcoB

    Participant

    786 Points

    146 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 06, 2007 04:45 PM | LINK

    BrowserHttpWebRequest is a thin wrapper around the browser's XMLHttpRequest object. As such, this completely depends on the ability of the browser to enable cross-domain requests.

    That said, we've had several customers show interest in cross-domain support, and as such this is definitely something high on our list. Obviously, to enable this we would be abstracting the OS HTTP stack rather than the browser's - at least for the cross-domain requests. And there would very likely be some consequences, such as no support for cookies to prevent XSS attacks.

    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • m3taverse

    m3taverse

    Member

    186 Points

    88 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 07, 2007 08:56 PM | LINK

    Is there a trick I'm missing in regard to debugging a Website project that includes a SL1.1a project and a Webservice?
    I'm pulling out my hairs over debugging this thing.

  • WilcoB

    WilcoB

    Participant

    786 Points

    146 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 08, 2007 12:07 AM | LINK

    Are you using VS2k5? Or "Orcas"? Are you unable to debug the webservice? Or the SL project? Or does neither of them work with the debugger? Can you get it working by attaching manually to the right process (w3wp/webdev.webserver.exe/aspnet_exe for the webserver to debug your webservice or iexplore.exe/firefox.exe for the browser to debug your SL app)?

    - Wilco Bauwer (MSFT) / http://www.wilcob.com
  • m3taverse

    m3taverse

    Member

    186 Points

    88 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 08, 2007 10:41 AM | LINK

    WilcoB

    Are you using VS2k5? Or "Orcas"? Are you unable to debug the webservice? Or the SL project? Or does neither of them work with the debugger? Can you get it working by attaching manually to the right process (w3wp/webdev.webserver.exe/aspnet_exe for the webserver to debug your webservice or iexplore.exe/firefox.exe for the browser to debug your SL app)?

     

    Thanks for trying to help me WilcoB, but it was my own lack of knowledge that was causing the real problems.
    Here's what I was doing ... i first made a webservice which I then put on IIS. Then I tried to make a SL project that used that webservice. Of course this does not work because of the cross domain limitation. So my next step was to make Web project that included both my Silverlight project, and the webservice. It then took me a while to figure out I can use ~ to signify the app root when referencing web services, which solved the problem of second guessing which port de dev server would use. So now my SL app was able to see the Web service as they were both running in the same web project.

    Then I ran into major problems on the Silverlight side when I tried to consume the webservice by using the normal web reference way of doing it. I still did not get that to work, it just crashes with a "Failed to invoke webservice" message, while the webservice itself is perfectly happy and consumable from any other app. I now use HttpBrowserRequest and that works great altho it requires more legwork.

    Anyway, what took me a bit of time to figure out was that I can actually debug the webservice, the web project and the Silverlight app at the same time by marking the right boxes in the Project Property Pages. Before I figured that out I was flying blind.

    So now everything is smooth and nice, and debugging the whole thing end to end works great.

  • Zodd

    Zodd

    Member

    30 Points

    13 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 10, 2007 08:18 PM | LINK

    Hey m3taverse ,

    Can you shed more light on this. I have the same issue. However I have the webservice and the SL project in the same solution but still get the cross domain error. How did you utilize the ~ to get around the issue when they are both in the same solution?

  • m3taverse

    m3taverse

    Member

    186 Points

    88 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 10, 2007 10:30 PM | LINK

    Hi Zodd.

    The ~ character can be used to signify the root of your Application.
    What I did to make it work.. I first published the webservice to IIS, then I added a reference to the webservice in my Silverlight project.
    Then I selected the reference to the webservice in the solution explorer, and in its properties I modified the URL to show ~/WebService.asmx  (was : http://localhost/mySite/WebService.asmx).  If you do this and then hit enter, VS will pick up on the webservice that is in your project and everything is well from there on in, you can run everything within the debug webserver without problems.

    However, I have still not managed to get parameters to work using the reference. I can do myWebService.HellloWorld(), I can't do myWebService.Echo("test").

  • samsp

    samsp

    Member

    282 Points

    96 Posts

    Microsoft

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 11, 2007 06:24 PM | LINK

    Here are some quick steps:

    a) Use cassini for the web server during development - doesn't require tweaking to enable debugging etc

    b) Create a website for the web service, either as a website or as a web application project. Configure the web service for json using the scriptservice attribute  on the service.

    c) Create your silverlight project to consume the web service, and add a web reference to the service

    d) From the web project add a silverlight link to the silverlight project - this will then copy the xaml and assemblies to the website and on every build.

    e) Use the silverlight control on an aspx page using the xaml control (drag'n'drop the xaml file onto the page) or copy the testpage to the website.

    f) Configure the website as the startup project and the test page as the start page. F5 and you should be able to debug both the silverlight code and the web service code.

  • hsabri

    hsabri

    Member

    16 Points

    11 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 14, 2007 11:33 PM | LINK

    were you able to solve this when you want to deploy outside of dev environment?  I'm able to reference, use, debug a website that has a silverlight link, which links to a webservice in the website.  when i publish and deploy to another server, i get the cross browser exception..

     

    anyone have some thoughts.... 

  • hsabri

    hsabri

    Member

    16 Points

    11 Posts

    Re: Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?

    May 15, 2007 06:34 PM | LINK

     Does anyone know how to create a BrowserHttpWebRequest object. It doesn't come up in intellisense for me.