WCF介面的COM調用

來源:互聯網
上載者:User

服務介面往往會被跨平台、跨技術調用。使用非.NET技術(如asp, vb6)調用WCF服務介面時只能使用COM方式,通常有三種方法

1、使用SOAP SDK中的Soap對象

2、使用HTTPRequest對象

3、使用WCF的COM介面

其中第三種調用相對簡單,個人推薦使用。下面講一下第三種調用方式

為了滿足COM對象調用,.NET Framework3.5SP1把WCF代理介面註冊了COM組件對象,它就是Moniker對象,我們可以使用OLE Com Viewer工具來找到它

擷取這個對象可以使用GetObject方法。如下面的ASP代碼示範了如何擷取Moniker對象,並調用它

 1 <%
2 Response.write "Coding started!"
3 Response.write"</br>"
4
5 Dim mexMonikerString
6 Dim mexServiceMoniker
7
8 mexMonikerString = "service:mexAddress=http://xxxxx.aaaa.com:81/WcfService1/Service1.svc?wsdl"
9 mexMonikerString = mexMonikerString + ", address=http://xxxx.aaaa.com:81/WcfService1/Service1.svc/"
10 mexMonikerString = mexMonikerString + ", binding=WSHttpBinding_IService1,bindingNamespace=http://tempuri.org/"
11 mexMonikerString = mexMonikerString + ", contract=IService1, contractNamespace=http://tempuri.org/"
12
13 Set mexServiceMoniker=GetObject(mexMonikerString)
14
15 mexServiceMoniker.ChannelCredentials.SetUserNameCredential "WCFCaller", "WCFCaller"
16 Response.write mexServiceMoniker.Echo("sss")
17
18
19 Set mexServiceMoniker = Nothing
20 %>

調用GetObject方法時使用的參數包含了:

1、中繼資料交換地址。

     指的是WCF介面的WSDL檔案地址

2、服務地址

     指的是WCF介面的服務地址,即svc檔案的URI。

3、綁定名

     WSDL檔案中的   wsdl:binding 配置節, name 屬性

4、服務契約名

     WSDL檔案中的 wsdl:portType 配置節, name屬性

 如果以上配置都正確,調用時還是出錯的話,很可能是你的服務介面中包含了物件類型的參數或傳回值,這些資料無法在非.net環境中被封裝。所以如果你的WCF介面需要被跨技術調用, 請一定要使用簡間資料類型的介面參數和傳回值。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.