Skip to main content
Home Forums Silverlight Programming Programming with .NET - General WCF Service problem
15 replies. Latest Post by StefanG on October 11, 2008.
(0)
StefanG
Member
10 points
25 Posts
10-09-2008 6:00 PM |
Hi All,
I mentioned this in another thread but it was a bit off-topic so I decided to start a dedicated thread. I have deployed a WCF service and my Silverlight application on a server (not where I develop). When opening the application from the server (not even cross-domain) I get the following error:
Microsoft JScript runtime error: Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at MySilverlightProject.MyService.MyServiceMethodCompletedEventArgs.get_Result() at MySilverlightProject.App.client_MyServiceMethodCompleted(Object sender, MyServiceMethodCompletedEventArgs e) at MySilverlightProject.MyService.MyServiceClient.MyServiceMethodCompleted(Object state)
Just in case I do have the crossdomain.xml and clientaccesspolicy.xml in the root folder of the Silverlight application. Furthermore I tried to reference the WCF service from a simple Windows Forms app and it worked smoothly. Also within my Silverlight application I use literally the same (copy & pasted) routine as in the windows forms app, this includes setting up a BasicHttpBinding and Endpoint objects.
Any ideas on how I can debug this and get more information about what actually went wrong and what the problem is?
Thanks,
Stefan
pbromberg
Participant
1984 points
353 Posts
10-09-2008 8:40 PM |
You really need to post a more complete code sample for this, in order to expect more meaningful help posts. The key thing I see here is "Microsoft JScript runtime error". Can you post some sample code please?
amit_pal...
1150 points
201 Posts
10-10-2008 3:24 AM |
"I do have the crossdomain.xml and clientaccesspolicy.xml in the root folder of the Silverlight application"
You do not need to place these files in Silverlight application rather on the root folder of your webserver. For e.g, if you are using IIS, then it will be C:\inetpub\wwwroot.
You can place any of these files and that should work however for more flexibility, it is advisable to put only clientaccesspolicy.xml. This is the file which will be checked first and if this is not found then it checks for crossdomain.xml. So, just copying clientaccesspolicy.xml will do the job.
Please mark the post as 'Answered' if this Answers your question
HarshBar...
Star
9908 points
1,719 Posts
10-10-2008 3:26 AM |
Hi,
I don't think it is policy file which is causing the issue(As it can not be javascript).I think it is some thing else.
Please proveide some more details for this.
10-10-2008 3:44 AM |
Thanks for the prompt replies.
Bellow is the code I use to call the service from within Silverlight. The reason I didn't post code is because when I was developing both the WCF service and the Silverlight app I had them in one solution (so no cross-domain calls) and they were working fine.The problems started appearing when I deployed them to the server. I was hoping this would be a common error :)
Anyway.. this is how I call the service. The code resides in private void Application_Startup(object sender, StartupEventArgs e) in App.xaml.cs because I need to fetch the data and use it to initialize my canvas:
BasicHttpBinding bind = new BasicHttpBinding(); EndpointAddress endpoint = new EndpointAddress("http://192.168.1.69:5554/CRMProxyService.svc");
CrmProxyService.CRMProxyServiceClient client = new CRMProxyServiceClient(bind, endpoint); client.GetRelationSubjectCompleted += new EventHandler<GetRelationSubjectCompletedEventArgs>(client_GetRelationSubjectCompleted); client.GetRelationSubjectAsync("{A0E89268-37E6-DC11-A6B2-0003FF38484A}");
The callback method simply initializes the page:
void client_GetRelationSubjectCompleted(object sender, GerRelationSubjectCompletedEventArgs e) { RootVisual = new Page(e.Result); }
As for the deployment, the server is a VPC. I have deployed the WCF Service and the Silverlight app as two separate websites in IIS.
As for the cross domain xml files, I did just now put them in the wwwroot as well as in the actual website root of the Silverlight website (I thought that's where they should be) but I still get the same thing. In addition when I open the Silverlight website from within the server (no cross-domain?) I still get the same exact error.
brauliod
1163 points
469 Posts
10-10-2008 6:12 AM |
There must be some silly small detail over there, check out this post
http://blogs.msdn.com/cesardelatorre/archive/2008/09/29/using-silverlight-2-0-clientaccesspolicy-xml-vs-crossdomain-xml-for-web-service-cross-domain-access.aspx
Good luck
Braulio
10-10-2008 6:27 AM |
Thanks for the reply Braulio.
The only difference that I could see between my setup and the post is that the clientpolicy.xml was different.
Mine was:
<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy> <allow-access-from domain="*" /></cross-domain-policy>
and the post suggests I use
<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy> <allow-http-request-headers-from domain="*" headers="*"/></cross-domain-policy>
I changed it the but error stays exactly the same. Also, for reference, this is my clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?><access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access></access-policy>
10-10-2008 7:58 AM |
Just a silly question, does your web service call return a lot of data? It should fail as well on your dev environment (if you use the same data), I face that some weeks ago, and It take me some time to realize that I had to setup a bigger buffer.
party42
1076 points
329 Posts
10-10-2008 8:03 AM |
it was something like this. dont have visual studio here so not sure about syntax but something like below should work.
1 BasicHttpBinding binding = new BasicHttpBinding(); 2 binding.MaxReceivedMessageSize = 2147483647; // int's max size 3 binding.MaxBufferSize = 2147483647; // int's max size 4 EndpointAddress endpoint = new EndpointAddress("http://192.168.1.69:5554/CRMProxyService.svc")
edward_494
149 points
86 Posts
10-10-2008 9:42 AM |
about the clientaccesspolicy.xml fle. where does it need to go when running in development? i currently have it in the folder/project root level of my service.
10-10-2008 11:43 AM |
If your service is running to http://yourserver.com/service/abc.svc then it should always go to "http://yourserver.com/clicntacesspolicy.xml ".
NeilChen
17 points
10 Posts
10-10-2008 12:00 PM |
I suggest you to use Fiddler or some other HTTP watching tool to see the exact WCF error messages. After that you can easily tell if the problem is related to clientpolicy.xml settings.
10-10-2008 12:31 PM |
Thanks for the reply and for the idea. I ran Fiddler from within the server and this is what I got:
The blacked-out is my apps.
It looks very weird... when I manually try to access clientaccesspolicy.xml and crossdomain.xml I can. They open up in the browser nicely. However when Silverlight tries to access them it gets a 404. Any ideas?
10-10-2008 1:30 PM |
If you are playing with Cassini you need to configure the path, to make the app run on the root folder, and place the xml file in the root of your project.
For a real IIS deployment, must be in the IIS root, that's a pain on the neck if you are sharing hosting :-).
HTH
sladapter
All-Star
17181 points
3,133 Posts
10-10-2008 8:15 PM |
StefanG:As for the deployment, the server is a VPC. I have deployed the WCF Service and the Silverlight app as two separate websites in IIS. As for the cross domain xml files, I did just now put them in the wwwroot as well as in the actual website root of the Silverlight website (I thought that's where they should be) but I still get the same thing. In addition when I open the Silverlight website from within the server (no cross-domain?) I still get the same exact error.
1) The clientaccesspolicy.xml file only needs to be at the wwwroot folder of the Server that host your WCF service and only one file is needed (either clientaccesspolicy.xml or crossdomain.xml).
2) What do you mean by "When I open the Silverlight web site from within the same server"? If you mean you open up a browser on the server machine to run your silverlight page, this does not change the call from cross-domain to non-cross-domain. Because you put WCF Service in another website than the webSite that host your Silverlight page. So they are cross-domain call no matter where you run your page.
To understand what is cross-domain call and most of the possible causes for Service error, read this thread: http://silverlight.net/forums/p/24005/86700.aspx#86700
3) If the error message is still refering to JScript, then it's not likely a cross-domain issue. Have you had your code worked before you deploy it to IIS? Do you have a particular reason to put the WCF service into another WebSite instead of putting it under the same WebSite that host your page? There is nothing wrong with that, it is just little hard to debug this way.
10-11-2008 10:52 AM |
Thanks. You're a life saver. The linked post was very helpful as well. What I did is to simply put the service and the silverlight page as two virtual directories in the same web page and that seemed to resolve the problem. I still a bit (not too much though :) ) curious as to what went wrong. I had the clientaccesspolicy.xml and crossdomain.xml under the root of the Silverlight page and not the service. Perhaps that's why?
Anyway, thanks a lot for your help!