Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Silverlight and WCF
13 replies. Latest Post by vijaynrm on May 14, 2008.
(0)
jelly
Member
6 points
5 Posts
05-15-2007 5:08 AM |
I noticed from Scott Guthrie's blog that he claims that Silverlight can be used to call WCF web services hosted within ASP.NET. I think the critical part of this statement must be that the web service must be hosted within ASP.NET since I can't find any way of directly interacting with WCF from Silverlight due to the subset of the CLR available. Has anyone else tried to do this, or know where there might be a nice example of doing this?
A bit later...
OK, I've managed to make some progress. I can create a WCF service which is hosted within ASP.NET. I can create a service reference and call the service from a Windows Forms application, so I'm happy that the service is running OK. However, I can't call the service from Silverlight. If I add it as a web reference and then try to call my method on it I get a (very helpful) error which states 'Error invoking service'. If I create a BrowserHttpWebRequest http://localhost/test/test.svc/Hello, or try the same thing in a browser, the response I get is:
I think this is something to do with the SOAP headers not being created correctly?
Has anyone else seen this problem, or have any ideas how to fix it?
Mike Rou...
4 points
2 Posts
05-15-2007 6:59 PM |
This is possibly due to the fact that, for security, Silverlight pages can only call web services that live on the same host as they do. For example, I have a web service I host at http://MikesComputer/... I can only call webservices there if the Silverlight page calling them lives on http://MikesComputer as well. Also, in my experience, referring to the web reference as localhost is not good enough. The Silverlight page will need to refer to the host's name so that Silverlight can be sure that it's the same as its own host.
In my own coding, I fixed this by removing my web reference to http://localhost webservices and adding references to those same web services as http://MikesComputer (which works because that's also the server hosting my Silverlight page).
Hope that this helps!Mike
05-16-2007 3:35 AM |
I don't think that's the problem since I've tried both localhost and the machine name. I can also access 'normal' webservices all right, this only becomes a problem when I try and access a WCF service (using a .svc file).
John
Zhenlan ...
80 points
35 Posts
05-16-2007 4:11 AM |
You need to make the WCF service using JSON as communication data format.
05-16-2007 4:50 AM |
There doesn't appear to be a lot of information on how to do this! I assume that it's either a matter of attributing the service or editing the configuration file?
luisabreu
Participant
1676 points
612 Posts
05-16-2007 5:29 AM |
hello.
take a look here:
05-16-2007 5:34 AM |
hello again.
sorry, wrong link. i think this is what you want:
http://blogs.msdn.com/mwinkle/archive/2007/02/28/wcf-and-wf-in-quot-orcas-quot.aspx
05-16-2007 6:47 AM |
I'm not sure that I'm going about this in the right way. I assume that if I am hosting my WCF service in IIS then the configuration settings are held in the web.config file? I've attempted to edit my web.config to match the example in the link above and the closest I've got (that doesn't cause errors) is:
<?xml version="1.0"?><configuration> <system.serviceModel>
<bindings> <webHttpBinding> <binding name="jsonBinding" messageEncoding="Json" /> </webHttpBinding> </bindings>
<
</
However, this then has no effect and I continue to get my error that the service cannot be processed at the receiver, due to an AddressFilter mismatch at the EndPoint dispatcher. It suggests that I should check that the sender's and receiver's EndPoint addresses agree. How would I be able to do that?
suyog kale
188 points
99 Posts
02-25-2008 10:39 PM |
hi jelly,
i am also trying to call WCF service from Silverlight application, WCF service hosted on same domain,
problem is when i return large data from Service it gives me MaxRecivedMessageSize is greater than 64Kb
so can you help me if you found any help, i tryed to set MaxRecivedMessageSize in web.config as well as app.config but it stilll not working
plz guide me, its very urgent for me
Bill Reiss
Contributor
4840 points
919 Posts
02-25-2008 11:00 PM |
You're really probably better off waiting for the Beta, since you'll probably have to rewrite it anyway, and the issues you're running into may be fixed in the Beta. It's not like you can deploy a 1.1 application, so you might as well wait.
HossamZain
2 points
1 Posts
05-12-2008 11:28 AM |
you just need to add clientaccesspolicy.xml to your WCF service
check : http://spellcoder.com/blogs/hossam/archive/2008/05/12/13475.aspx
MyMindsOwn
52 points
22 Posts
05-12-2008 4:15 PM |
You don't need to connect using JSON serialization, SOAP will work just fine, but you can't use the ChannelFactory to communicate with your service, you must add a service reference. You might be having some cross domain issues, judging from the "DestinationUnreachable" message. To be sure that's not it you can follow the instructions from one of the previous responses.
Jeff Cao...
201 points
29 Posts
05-13-2008 3:09 PM |
Do note that we currently only support BasicHttpBinding on Silverlight side.
vijaynrm
70 points
10 Posts
05-14-2008 2:33 AM |
This seems to be a cross-domain issue with silverlight.
A silverlight control hosted at http://MyMachine/mycontrol.aspx can only access services on that same domain by default , for example: http://MyMachine/service.svc, not a service at http://OtherMachine/service.svc.
To enable this, the service must explicitly opt-in to allow cross-domain access, for that we need to add a clientaccesspolicy.xml file at the root of the domain where the service is hosted to configure the service to allow cross-domain-access
clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?><access-policy> <cross-domain-access> <policy> <allow-from> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access></access-policy>
For more details :http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx
- Vijay Narayan