下面的範例是在網路上看到的.net版本的解決方式。

End Point指的是Web Service WSDL的URL。

要做到動態設定Web Services,可以依照以下步驟設定:

1. 加入Web Service參考,這裡我們假設Account,服務位址http://mywebservice.services.com.tw/web/account.asmx,並且將「Web參考名稱」改換成AccountServices。

2. 在程式中,建立Account的Proxy物件,並更新其服務位址來達到動態選擇位址的目的:

using AccountServices;

 protected void Page_Load(object sender, EventArgs e)

 { /* 建立Proxy物件 */ Account acc = new Account();

 /* 切換服務位址 */

 acc.Url = http://mywebservice.services.com.tw/web/account.asmx;

 acc.Discover();

 //根據Url設定尋找新的服務位址

 MsgLbl.Text = acc.Login("XXX", "david", "davidpwd");

/* 切換服務位址 */

 acc.Url = http://mywebservice.services.com.tw/web/account.asmx;

 acc.Discover(); //根據Url設定尋找新的服務位址 MsgLbl2.Text = acc.Login("XXX", "david", "davidpwd");

只要利用Proxy物件的Url以及Discover方法,就可以動態的指定我們想要更換的Web Services位址。

接下來再搭配Web.Config的組態設定,位置的更換就方便了。

 

參考資料來源:
http://www.ithome.com.tw/plog/index.php?op=ViewArticle&articleId=4741&blogId=586 ----- 

 

arrow
arrow
    全站熱搜

    白努力電腦日記 發表在 痞客邦 留言(0) 人氣()