Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How to Use WebService? RSS

4 replies

Last post Jun 25, 2007 09:29 AM by luisabreu

(0)
  • zhang.cq

    zhang.cq

    Member

    2 Points

    5 Posts

    How to Use WebService?

    Jun 08, 2007 07:40 AM | LINK

     I want to call webservice in my silverlight project. I have tried many many times but still not work. Here is my step:

    1.New a ASP.NET Web Service (WebSite1) ,run it.Test the "HelloWorld" function.

    2.New a Silverlight Project(SilverlightProject1) and run it.

    3.Add Existing project (SilverlightProject1) into WebSite1.

    4.Add Silverlight link.

    5.set the TestPage.html as the default page of Website1.

    6.in Silverlight Project1, "Add Web Reference",then Select "Web services in this solution". Click "Service" and name it "GetHelloWorld".

    7.in Page.xaml.cs. Add the following two lines:

                                GetHelloWorld.Service testWebService = new GetHelloWorld.Service();
                                string testString= GetHelloWorld.HelloWorld();

    8.run SilverlightProject1. It may say "This Silverlight project you are about to debug is consuming WebService",Calls the WebService will fail unless the project is executed in the context of the web which contains the Web service."        Click "yes" to continue;

    9.run WebSite1. when call GetHelloWorld.HelloWorld() , I get a exception "operation is not valid due to the current stage of object"

    why? How to use Webservice in silverlight correctly?

    Thanks
     

  • nerddawg

    nerddawg

    Member

    516 Points

    123 Posts

    Microsoft

    Re: How to Use WebService?

    Jun 09, 2007 01:20 PM | LINK

    Here is a tutorial on how to use web services with Silverlight.

    Can you also confirm that you have the following attribute on your WebService -derived class?

    [System.Web.Script.Services.ScriptService]

    My understanding is 1.1 Alpha only supports JSON serialization (I could be wrong here but its worth trying)

    Ashish Shetty | Program Manager | Microsoft
    Blog: http://nerddawg.blogspot.com
  • bibildiploop

    bibildiploop

    Member

    18 Points

    15 Posts

    Re: How to Use WebService?

    Jun 10, 2007 09:04 AM | LINK

    "My understanding is 1.1 Alpha only supports JSON serialization (I could be wrong here but its worth trying)"

     I believe you're right on that one. If its just a regular .net web service, he should get a JSON incorrect type style error. At least i did when trying to access my web service. If you download the asp.net futures here

     http://www.asp.net/downloads/futures/default.aspx?tabid=62 

     It has everything to create a scriptable web service. I also found this source quite useful in accessing a JSON service :

    http://silverlight.net/QuickStarts/ViewSample.aspx?sref=Silverlight.net.json/cs/webservice.cs

    Its basically a web service proxy and it works quite will with the above web services

    JSON web service futures ScriptService

  • Meta-Peeyush

    Meta-Peeyush

    Member

    2 Points

    1 Post

    Re: How to Use WebService?

    Jun 25, 2007 04:50 AM | LINK

     This is not working for me too. I have followed all the steps discussed above. The web service call does not throw any error but hangs indefinitely. In debug mode it is the call to the operation exposed in the web-service that hangs up.

    long n = utilService.Multiply(2, 3); 

     Thanks,

    Peeyush
     

  • luisabreu

    luisabreu

    Participant

    1676 Points

    612 Posts

    Re: How to Use WebService?

    Jun 25, 2007 09:29 AM | LINK

    hello.

    if you're calling an asmx web service you need to drop the web extensions dll (asp.net ajax 1.0 dll) and you need to modify the web.config so that a new handler is used to managed asmx service calls. besides taht, you need to annotate your web services with some new attributes. i believe that the quickstarts omit some of these steps.

    you can also call wcf services and this is also easy after configuring your wcf web service to use json. i've written about it here:

    http://msmvps.com/blogs/luisabreu/archive/2007/06/13/calling-a-silverlight-wcf-service-part-ii.aspx

    http://msmvps.com/blogs/luisabreu/archive/2007/06/12/calling-a-wcf-service-from-your-silverlight-application.aspx

    http://msmvps.com/blogs/luisabreu/archive/2007/06/11/calling-web-services-from-your-silverlight-alpha-app.aspx