Web service calling for Windows Phone 7 Network Programming

Source: Internet
Author: User

The following example shows the Windows Phone 7 app through a mobile phone number attribution query.ProgramHow to call the Web service interface.

Let's take a look at the running effect:

The app calls the following Web Service Interface for phone number attribution query:

Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx

The first step is to add a reference to the WebService and add the web service. Then, a local proxy of the web service is generated.

Because. the net platform has built-in support for Web Services, including the construction and use of web services, therefore, in the Windows Phone 7 project, you can complete Web service development without other tools or sdks.

After a web service reference is added, the project's file directory is as follows:

Added the assumereference service and the servicereferences. clientconfig file.

Step 2 call Web Service

First Look At The XAML InterfaceCode

 <  Grid  X: Name  = "Contentpanel"  Grid. Row  = "1"  Margin  = "12, 0, 12, 0"  >  
< Textblock Height = "49" Horizontalalignment = "Left" Margin =" Name = "Des" Text = "Enter the phone number you want to query" Verticalalignment = "TOP" Width = "284" />
< Textbox Height = "72" Horizontalalignment = "Left" Margin = "6,106" Name = "No" Text = "" Verticalalignment = "TOP" Width = "415" />
< Button Content = "Query" Height = "72" Horizontalalignment = "Left" Margin = "12,184" Name = "Search" Verticalalignment = "TOP" Width = "160" Click = "Search_click" />
< Textblock Height = "211" Horizontalalignment = "Left" Margin = "6,277" Name = "Information" Text = "" Verticalalignment = "TOP" Width = "444" />
</ Grid >

The code for calling the Web Service is concise...

 Public     Partial    Class  Mainpage: phoneapplicationpage
{
Public Mainpage ()
{
Initializecomponent ();
}

Private Void Search_click ( Object Sender, routedeventargs E)
{
// Instantiate a Web Service proxy object
Mobilereference. mobilecodewssoapclient proxy = New Mobilereference. mobilecodewssoapclient ();
// Events triggered after the call of the getmobilecodeinfo method ends
Proxy. getmobilecodeinfocompleted + = New Eventhandler < Assumereference. getmobilecodeinfocompletedeventargs > (Proxy_getmobilecodeinfocompleted );
// Add the call information, including method names and parameters, to the SOAP message and send it to the Web Service server over HTTP.
// The getmobilecodeinfo method of Web Service is called.
Proxy. getmobilecodeinfoasync (No. Text, "" );
}

Void Proxy_getmobilecodeinfocompleted ( Object Sender, assumereference. getmobilecodeinfocompletedeventargs E)
{
If (E. Error = Null )
{
// Display returned results
Information. Text = E. result;
}
}
}

OK ....

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.