Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug REST Service in Silverlight
3 replies. Latest Post by Min-Hong Tang - MSFT on November 3, 2009.
(0)
gareesilver
Member
17 points
14 Posts
10-28-2009 3:16 AM |
Hi,
I wrote a Rest Service in WCF. My method look like this
[OperationContract] [WebInvoke(UriTemplate = "/Insert", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] string InsertNumbers(NumberService num);
I hosted my service in IIS and when i try to run it using my ip addr, It asks for username and Password. But when i gave it is not accepting.
Also i am unable to call this service from Silverlight. I used like this in Xaml.cs file.
WebClient cnt = new WebClient(); Uri uri = new Uri(baseuri); cnt.DownloadStringAsync(uri); cnt.DownloadStringCompleted += new DownloadStringCompletedEventHandler(cnt_DownloadStringCompleted);
Can anyone help me in this issue?
ken tucker
All-Star
16346 points
2,499 Posts
10-28-2009 6:09 AM |
I am not really an expert at creating rest services but you need a way in the uri template to pass in the parameter
<OperationContract()> _ <WebGet(UriTemplate:="map/user/{MapId}", ResponseFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Bare)> _ Function ListUsersForMap( ByVal MapId As String) As List(Of String)
I do not think it is possible to pass a complex type (NumberService) to a rest service.
10-28-2009 6:20 AM |
Hi Ken,
Thanks for your reply. But i saw an example for passing complex types to rest.I think, Pbm is not in complex type. I am unable to call the normal service methods also.
Min-Hong...
Contributor
3578 points
408 Posts
11-03-2009 1:10 AM |
My opinion is , there is something wrong when you call the wcf service. May i see the download uri string there.
Here is my example, I tested it.
My Service Contract :
public interface IRestService { [OperationContract] [WebGet(UriTemplate = "/GetData?id={s}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] string GetData(string s); }
My Calling:
WebClient webClient = new WebClient(); WebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted); webClient.DownloadStringAsync(new Uri("http://localhost:29595/MyRestService.svc/GetData?id=3333"));
Usually when i debug my wcf program i will follow 4 steps you can take a look:
1st : Right click the svc file to show it in the browser. By this means, i can find out if the wcf service is working properly.
2nd: Check the configuration file, you know there is limitations for silverlight to communicate with services.
3rd: Check cross domain issues, or firewall things.
4th; Check the client application. Make sure it went to the right place for being served.
Since you saide your silverlight applicaton can not even communicate with a normal service , you may debug as the order i mentioned. It always helps me.
Best Regards