locked
C# Windows store 8 connecting non-wcf web services RRS feed

  • Question

  • Hi all, I create a login page for windows store 8 app using visual studio 2012 ultimate. My login function is in .asmx web service which is under framework 3.5. How I can send the username and password to the web service and receive a return ? Thanks. : )
    Wednesday, August 28, 2013 2:00 PM

Answers

  • OK, here is how you can do it:

    - Create a blank C#/XAML app called ConsumeWS

    - Add a reference to the above service and call it: DBService

    - Add a button and add a Click handler to the button

    - In the click handler, use the below code:

            private async void Button_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    ConsumeWS.DBService.Service1SoapClient client = new ConsumeWS.DBService.Service1SoapClient();
                    ConsumeWS.DBService.loginwebResponse response = await client.loginwebAsync("username", "password");
                    string result = response.Body.loginwebResult;
                }
                catch (Exception oEx)
                {
                    // handle the Exception
                }
            }


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Thursday, September 12, 2013 6:26 PM
    Moderator
  • The IP Address that you are getting an exception on is a Private IP (10.230.5.27).

    The exception is thrown because you do not seem to have the right type of manifest settings enabled. To get past this exception open the Package.appxmanifest file, go to Capabilities tab and check the checkbox that says "Private Networks (Client & Server)".


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Thursday, August 29, 2013 5:39 PM
    Moderator

All replies

  • Even if your target Web Service is ASMX based, you can still add a "Service Reference" to your Windows Store app and consume your Web Service. Are you getting any errors when adding a Service Reference to your project?

    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    • Proposed as answer by Dave SmitsMVP Thursday, August 29, 2013 8:32 AM
    Wednesday, August 28, 2013 9:42 PM
    Moderator
  • No, i can add the service reference but the problem is I cannot call the function in web-service. i have done the coding to call the function such as login but it shows an error. i have try many method at google but it still cant working. could you help me sir? i still new in this field. i will attach the picture of the error...

    • Edited by asekau Thursday, August 29, 2013 1:49 PM
    Thursday, August 29, 2013 1:21 PM
  • The IP Address that you are getting an exception on is a Private IP (10.230.5.27).

    The exception is thrown because you do not seem to have the right type of manifest settings enabled. To get past this exception open the Package.appxmanifest file, go to Capabilities tab and check the checkbox that says "Private Networks (Client & Server)".


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Thursday, August 29, 2013 5:39 PM
    Moderator
  • Thank you sir for helping me to solve this problem....
    Saturday, August 31, 2013 7:04 AM
  • Hi everyone, I'm new in C# and windows store 8. I have the same question with this post. I already add the service reference. The problem now is I don't know the codes. I want to call the web service and show the return. How can I do this ? There are lots of reference shown in google and I get confuse myself because none is work for me. Maybe because I implement it wrongly. Can anyone tell me the right one ?

    Thanks. : )

    for reference

    method : loginweb

    variable : username, password

    url : http://61.14.148.30/dbservice/service1.asmx


    • Edited by diam je Thursday, September 12, 2013 12:11 PM
    Thursday, September 12, 2013 2:07 AM
  • OK, here is how you can do it:

    - Create a blank C#/XAML app called ConsumeWS

    - Add a reference to the above service and call it: DBService

    - Add a button and add a Click handler to the button

    - In the click handler, use the below code:

            private async void Button_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    ConsumeWS.DBService.Service1SoapClient client = new ConsumeWS.DBService.Service1SoapClient();
                    ConsumeWS.DBService.loginwebResponse response = await client.loginwebAsync("username", "password");
                    string result = response.Body.loginwebResult;
                }
                catch (Exception oEx)
                {
                    // handle the Exception
                }
            }


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Thursday, September 12, 2013 6:26 PM
    Moderator
  • Thanks ! In case there are anyone who have the same problem, the following is the codes.

      private async void login()
            {

                try
                {
                    App1.ServiceReference1.Service1SoapClient client = new App1.ServiceReference1.Service1SoapClient();
                    App1.ServiceReference1.loginwebResponse response = await client.loginwebAsync(text1.text.ToString(), text2.text.ToString());
                    string result = response.Body.loginwebResult;
                    showTextBlock.Text = result;
                }
                catch (Exception Ex)
                {
                    show.Text = Ex.ToString();
                    // handle the Exception
                }

            }

            private void button_Click_1(object sender, RoutedEventArgs e)
            {
                login();
            } 



    • Edited by diam je Saturday, September 14, 2013 5:16 AM edit code
    Friday, September 13, 2013 12:39 PM
  • Another thing, beside trying on windows store, I also try the code for windows phone 8. But it happen to show as the following. What is the reason for this ?

    Friday, September 13, 2013 12:53 PM
  •  In Windows phone this is not the way to implement web service.

     make it  with completed event.

    Wednesday, April 2, 2014 6:39 AM