Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Disable Cross-Domain restrictions on BrowserHttpWebRequests for development?
20 replies. Latest Post by pkellner on June 18, 2007.
(2)
gmcbay
Member
6 points
6 Posts
05-05-2007 1:06 AM |
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
692 points
127 Posts
05-06-2007 12:45 PM |
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.
m3taverse
186 points
88 Posts
05-07-2007 4:56 PM |
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.
05-07-2007 8:07 PM |
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)?
05-08-2007 6:41 AM |
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
30 points
13 Posts
05-10-2007 4:18 PM |
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?
05-10-2007 6:30 PM |
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
282 points
96 Posts
05-11-2007 2:24 PM |
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
16 points
11 Posts
05-14-2007 7:33 PM |
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....
05-15-2007 2:34 PM |
Does anyone know how to create a BrowserHttpWebRequest object. It doesn't come up in intellisense for me.
05-15-2007 2:36 PM |
for example, i can not do this:
HttpWebRequest request = new BrowserHttpRequest();
agstewart
14 points
7 Posts
05-15-2007 3:13 PM |
Check out the quickstart http://www.silverlight.net/QuickStarts/Remote/UsingREST.aspx
This worked for me.... BTW, I defined request as a BrowserHttpRequest, not an HttpWebRequest.
-- Added
Forgot to mention, if you import Windows.System.Browser.Net then the intellisense will work.
---
forci
351 points
275 Posts
05-16-2007 5:01 AM |
I install cassini, and i can debug my application, i didn't try to debug webService yet, but i have a basic question.
Is it possible to tell VS what URL must opened. If i press F5 VS open something like this:d:\Projects\SilverLight\Test1\TestPage.htm
but since i use cassini, i really want that VS orcas would opened my project with this URL:http://localhost/TestPage.htm
How to do that?
NickyM
10 points
8 Posts
05-16-2007 6:50 AM |
I go over all steps but i have error as yet. I have webserivce file in webservice project:
namespace WebServices{ [WebService(Namespace = "WebServices")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class TestService : System.Web.Services.WebService { public TestService() { } [WebMethod] public string HelloWorld() { return "Hello World"; } }}
I have xaml file in SilverLight project:using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace SilverLight.Test{ public partial class SlTest : Canvas { public void Page_Loaded(object o, EventArgs e) { // Required to initialize variables InitializeComponent(); SilverLight.WebServices.TestService fService = new SilverLight.WebServices.TestService(); string fStr = fService.HelloWorld(); } }}
and i have TestPage.html and TestPage.html.js in SilverLight project.
I add web reference to the web service.
I install Cassini and run TestPage on http://localhost/TestPage.html. In debug mode autogenerate file in row
object[] results = this.Invoke("...", new System.Windows.Browser.Net.SoapHttpClientProtocol.ServiceParameter[0], typeof(string));return Cross domain calls are not supported by BrowserHttpWebRequest error.
I don't know why i heve this problem.
Bye
Nicky
05-16-2007 8:28 AM |
I also have the same problem. I use cassini and i try to run this WebService, but i get the error:- base {"Cross domain calls are not supported by BrowserHttpWebRequest."} System.SystemException {System.InvalidOperationException}
My project run cassini: http://localhost/Tests/TestPage.html
and my WebService run VS Orcas: http://localhost:2752/TestService.asmx
As far as i know the project and WebService cannot run on same port? So how to solve the problem?
luisabreu
Participant
1676 points
612 Posts
05-17-2007 10:02 AM |
Hello.
WilcoB: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
After using reflector, this doesn't seem to be true. The public constructor redirects to the internal constructor which does indeed check for a crossdomain call. Since the enableCrossDomainCalls parameter is always set to false by the public constructor, it seems like we can't make any cross-domain calls with this object (which really sucks!)
pkellner
200 points
131 Posts
06-06-2007 4:13 PM |
what did you mark in project properties to get debugging services to work?
bpatters
50 points
24 Posts
06-07-2007 12:20 PM |
Is there any timeline or way to get this crossdomain support working? It's next to impossible to develop/debug an application you have to deploy to the server in order to run. Duplicating the Entire servers infrastructure on my laptop just to debug a silverlight user interface is not really realistic.
How do you step through a silverlight application that is deployed with the debugger?
06-07-2007 12:49 PM |
To test some things on existing webservices, I made a webservice in my Silverlight project that serves as a proxy to the actual online webservice.So SL calls the webservice in the local project, that webservice in turn retrieves the data from the actual webservice which lives on live webservers.
06-18-2007 10:30 AM |
Hi m3taverse,
I'm having trouble with the ~ solution. As you suggested, I change my reference to ~/WebService.asmx, and instead of getting the cross domain error, now I am getting this error. Any ideas?
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Windows.Browser.Net.BrowserHttpWebRequest.GetResponse()
at System.Windows.Browser.Net.SoapHttpClientProtocol.Invoke(String methodName, ServiceParameter[] parameters, Type returnType)
at WebService.EchoInput(String input)
at SearchLightCombined.Page.Page_Loaded(Object o, EventArgs e)
06-18-2007 9:22 PM |
So, I finally got this all figured out for myself, and to help spare others some pain, I wrote a blog post in detail of all the steps need to create a Silverlight .net project that includes a web service project. It's probably longer than it needs to be, but I just love pictures.
Thanks for everyone's help here. Here is the post.
http://peterkellner.net/2007/06/18/silverlightdebugwebservicedotnet/