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 ....