1.首先了解Web Service服務
1)Web Services 是一種構建應用程序的普通模型,並能在所有支持 Internet 通訊的操作系統上實施運行。Web Services 令基於組件的開發和 Web 的結合達到最佳,基於組件的對象模型,如:Distributed Component Object Model(DCOM)、Remote Method Invocation(RMI),Internet Inter-Orb Protocol(IIOP)都已經發布了很長時間了,但是這些模型都依賴於特殊對象模型協議,而 Web Services 利用 SOAP 和 XML對這些模型在通訊方面作了進一步的擴展以消除特殊對象模型的障礙。
Web Services 主要利用 HTTP 和 SOAP 協議是商業數據在 Web 上傳輸,SOAP通過 HTTP 調用商業對象執行遠程功能調用,Web 用戶能夠使用 SOAP 和 HTTP通過 Web 調用的方法來調用遠程對象.
1)Web Services 是一種構建應用程序的普通模型,並能在所有支持 Internet 通訊的操作系統上實施運行。Web Services 令基於組件的開發和 Web 的結合達到最佳,基於組件的對象模型,如:Distributed Component Object Model(DCOM)、Remote Method Invocation(RMI),Internet Inter-Orb Protocol(IIOP)都已經發布了很長時間了,但是這些模型都依賴於特殊對象模型協議,而 Web Services 利用 SOAP 和 XML對這些模型在通訊方面作了進一步的擴展以消除特殊對象模型的障礙。
Web Services 主要利用 HTTP 和 SOAP 協議是商業數據在 Web 上傳輸,SOAP通過 HTTP 調用商業對象執行遠程功能調用,Web 用戶能夠使用 SOAP 和 HTTP通過 Web 調用的方法來調用遠程對象.
2)對Web Services的詳細講解來源博客:
3)Web Services的教程:
2.添加引用Web Service服務
1)應用調用的手機號碼歸屬地查詢的web service接口爲:
2)添加Web Service服務
圖片暫時沒有傳上
3.後臺的調用web service服務
private void Search_Click(object sender, RoutedEventArgs e)
{
//實例化一個web service代理的對象
MobileReference.MobileCodeWSSoapClient proxy = new MobileReference.MobileCodeWSSoapClient();
{
//實例化一個web service代理的對象
MobileReference.MobileCodeWSSoapClient proxy = new MobileReference.MobileCodeWSSoapClient();
proxy.getMobileCodeInfoCompleted +=new EventHandler<MobileReference.getMobileCodeInfoCompletedEventArgs>(proxy_getMobileCodeInfoCompleted);
//將調用信息包括方法名和參數加入到soap消息中通過http傳送給web service服務端
//這裏對應的是調用了web service的getMobileCodeInfo方法
proxy.getMobileCodeInfoAsync(TextBox_Phonenumber.Text, "");
}
//這裏對應的是調用了web service的getMobileCodeInfo方法
proxy.getMobileCodeInfoAsync(TextBox_Phonenumber.Text, "");
}
void proxy_getMobileCodeInfoCompleted(object sender, MobileReference.getMobileCodeInfoCompletedEventArgs e)
{
if (e.Error == null)
{
//顯示返回的結果
TextBlock_INFO.Text = e.Result;
}
}
{
if (e.Error == null)
{
//顯示返回的結果
TextBlock_INFO.Text = e.Result;
}
}
4.對控件屬性的附加(個人需求)
1)在源碼中使用了textbox的TelephoneNumber屬性
<TextBox Name="TextBox_Phonenumber"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Height="80"
Width="406"
Margin="23,112,0,0">
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="TelephoneNumber"></InputScopeName>
</InputScope>
</TextBox.InputScope>
</TextBox>
VerticalAlignment="Top"
HorizontalAlignment="Left"
Height="80"
Width="406"
Margin="23,112,0,0">
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="TelephoneNumber"></InputScopeName>
</InputScope>
</TextBox.InputScope>
</TextBox>
2)對textbox屬性的詳解,來源博客: