Skip to main content

Microsoft Silverlight

Unanswered Question REST Service in SilverlightRSS Feed

(0)

gareesilver
gareesilver

Member

Member

17 points

14 Posts

REST Service in Silverlight

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
ken tucker

All-Star

All-Star

16346 points

2,499 Posts

Re: REST Service in Silverlight

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.

gareesilver
gareesilver

Member

Member

17 points

14 Posts

Re: Re: REST Service in Silverlight

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 Tang - MSFT
Min-Hong...

Contributor

Contributor

3578 points

408 Posts

Re: Re: REST Service in Silverlight

Hi,

   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

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities