locked
WebServices In metro UI RRS feed

  • Question

  •                                        

    Hi ,

    I'm using VS2012 RC and I'm trying to call a webservice that I have created.

    I remember in Silverlight I was able to create a proxy and proceed with the implementation. Call my webservice functions , get data etc.

    Now I can still do this in VS2012 add a service reference but I'm curious if this is the appropriate method-way to use when writing Metro UI apps.

    So what I did 

    I added the Service reference with the usual way,

    Declare it

    My_Srv.n_srvSoapClient proxy;
    EndpointAddress MyEndPointAddress;


    and call it

    proxy = new My_Srv.n_srvSoapClient();
                    this.MyEndPointAddress = new EndpointAddress("http://myurl/asmx blabla");
                    string mystring = "";
                    f_loginResponse result = await proxy.f_loginAsync(txtUserName.Text, txtPassword.Password, mystring);



                    if (result.Body.f_loginResult.Contains("test"))
                    {
                    //I'm OK and Have DATA.

                    }


    And I am asking.

     Is the above code the correct way to call a webservice from a Metro UI APp?  
    I don't want to use the httpClient = new HttpClient(); ( I found an example for that ) 
    Does anyone has a good example on how to call a webservice from a Metro UI App and get the result ? 
    How am I suppose to check the status of the call ?? 
    And Something difficult. As we know Metro is Asynchronous. 
    How can I make synchronous calls for my web service.  

    I would appreciate any help you could give me.

    thank you



    • Edited by zakkar Monday, August 6, 2012 11:57 AM
    Monday, August 6, 2012 11:55 AM

Answers

  • Hi Zakkar,

    as far as I see the call is already asynchronous as you are calling f_loginAsync. It seems that VS already generated async methods for your webservice calls. Everything else should work like before (using standard / non-async .NET).

    But keep in mind that a Metro application is potentially running using a mobile Connection. Therfore you should think about using a REST/JSon based webservice instead of a classic SOAP Service. They normally cause a log of overhead. But this would require some knowledge in WCF of course.


    If you like my post or consider it as a valid answer, please use the buttons to show me - Oliver

    Microsoft Most Valuable Professional for BizTalk Server
    http://www.appfabric.de

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Monday, August 6, 2012 12:23 PM
  • the "best" always depends

    SOAP have Overhead, but ist ok and still works. You can take your Silverlight code and make it async

    Dim svc As ServiceReference1.service1SoapClient = New ServiceReference1.service1SoapClient
            Dim l = Await svc.ZeitAsync(args.QueryText)
            listview1.ItemsSource = l.Body.ZeitResult

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Monday, August 6, 2012 4:37 PM
  • Hi HannesPreishuber and thank you for your answer.

    I'm a little worried about using the soap. I know it works but...

    Microsoft suggests Httpclient.

    Oliver was talking about json. I found an example here

    http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee

    And it looks OK. Also I found the below

    http://blogs.msdn.com/b/henrikn/archive/2012/02/11/httpclient-is-here.aspx

    Perhaps I will drop the idea of using Soap and start using httpclient.

    If I want to call a method from a web service how do I do it ?

    Also I have one more question.

    How can I handle synchronous calls ?

    thank you

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Tuesday, August 7, 2012 4:12 AM
  • Hi,

    There is a sample about HttpClient in c#.

    http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664

    I think it quite simple to get JSON, the question is how to parse it. I've only found a article in c++:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770287.aspx

    Hope this helps


    Aaron Xue [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Friday, August 10, 2012 2:27 AM

All replies

  • Hi Zakkar,

    as far as I see the call is already asynchronous as you are calling f_loginAsync. It seems that VS already generated async methods for your webservice calls. Everything else should work like before (using standard / non-async .NET).

    But keep in mind that a Metro application is potentially running using a mobile Connection. Therfore you should think about using a REST/JSon based webservice instead of a classic SOAP Service. They normally cause a log of overhead. But this would require some knowledge in WCF of course.


    If you like my post or consider it as a valid answer, please use the buttons to show me - Oliver

    Microsoft Most Valuable Professional for BizTalk Server
    http://www.appfabric.de

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Monday, August 6, 2012 12:23 PM
  • Hi  Oliver and thank you for your answer.

    So , If I want to call a method from a webservice and get the data what is the best way to do this ?

    Do you have a working example for C# ?

    thank you

    Monday, August 6, 2012 12:35 PM
  • the "best" always depends

    SOAP have Overhead, but ist ok and still works. You can take your Silverlight code and make it async

    Dim svc As ServiceReference1.service1SoapClient = New ServiceReference1.service1SoapClient
            Dim l = Await svc.ZeitAsync(args.QueryText)
            listview1.ItemsSource = l.Body.ZeitResult

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Monday, August 6, 2012 4:37 PM
  • Hi HannesPreishuber and thank you for your answer.

    I'm a little worried about using the soap. I know it works but...

    Microsoft suggests Httpclient.

    Oliver was talking about json. I found an example here

    http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee

    And it looks OK. Also I found the below

    http://blogs.msdn.com/b/henrikn/archive/2012/02/11/httpclient-is-here.aspx

    Perhaps I will drop the idea of using Soap and start using httpclient.

    If I want to call a method from a web service how do I do it ?

    Also I have one more question.

    How can I handle synchronous calls ?

    thank you

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Tuesday, August 7, 2012 4:12 AM
  • no synchronous calls in WinRT ( and even in SL)

    dont missunderstand me. I am not pro SOAP. There are a lot a variables in game and REST ist not automaticly better. If you have a working wcf Service and know what you do, ist easier to start with the proxy way.

    Httpclient is a little more work. You have to generate all your custom datatypes in WinRT by code. At the end youhave more control about the wire

    Tuesday, August 7, 2012 5:07 AM
  • Hi ,

    Yes I know it is easier to use a proxy .

    Do you have a working  example where you can call a method from a webservice("asmx type") using httpclient or Json ?

    It would be great if I could have both.

    I cannot find anyone.

    thank you

    Tuesday, August 7, 2012 7:47 AM
  • Hi,

    There is a sample about HttpClient in c#.

    http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664

    I think it quite simple to get JSON, the question is how to parse it. I've only found a article in c++:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770287.aspx

    Hope this helps


    Aaron Xue [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aaron Xue Monday, August 13, 2012 2:35 AM
    Friday, August 10, 2012 2:27 AM