0

i have a web services which i am accessing in my client application(metro app) , but i want to access a particular method inside those many methods i have how should i do it ,

as of now , i am doing it in this way to accessing the web services from my metro app:-

private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string responseBodyAsText;
            HttpClient client = new HttpClient();
            HttpResponseMessage response = await client.GetAsync("http://182.134.34.99/OE/examplewebservices.svc");
            response.EnsureSuccessStatusCode();
            StatusText.Text = response.StatusCode.ToString();
            responseBodyAsText = await response.Content.ReadAsStringAsync();

        }

my requirement is :- there are many methods inside that examplewebservices , so i want to access one of the method inside that , pass input parameters to that method and get the result.

1)How to access one a particular method inside those many methods ( from metro app) ? 2)how to pass input to that service method (from metro app)?

Question might be very basic to you , pls help out. i am new to metro application development.

Thanks in advance.

user1516781
  • 973
  • 1
  • 20
  • 42

2 Answers2

0

The code you have does not call a service, it downloads service definition page. You will need to add a service reference to your project (right click on project node, choose Add Service Reference from context menu). Then you will be able to call methods of your service. In WinRT app, you will only be able to call web service asynchronously, so all methods will have 'Async' suffix and you will have to use async/await pattern when calling it.

seva titov
  • 11,720
  • 2
  • 35
  • 54
  • hi thanks for the reply , but my service reference url will be changing (in my app i give the user to enter a url in textbox) depending upon that i need to connect to that service , that is the reason i didnt follow the tradinal way of adding service refernce to the project to access the methods, please let me know how can i do if the service refernce url is changing. – user1516781 Jul 31 '12 at 07:00
  • You can configure service endpoint address with any URL at run time. See more details in this SO question: http://stackoverflow.com/questions/5036308/dynamically-switch-wcf-web-service-reference-url-path-through-config-file. – seva titov Jul 31 '12 at 15:50
0

To call an operation on the service you can use this pattern:

    using (HttpClient client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://182.134.34.99/OE/examplewebservices.svc");

            HttpResponseMessage response = await client.GetAsync("MyOperation");

            ...

        }

To send values in this simplistic example you can send them as QueryStrings appended to the MyOperation string as follows: MyOperation?myvalue=1 etc.

Other than that @Seva Titov gave a good response to the dynamic aspect.

Redeemed1
  • 3,953
  • 8
  • 38
  • 63