public class simpleobjectclass simpleobject inherits system.marshalbyrefobject
public function helloworld()function helloworld(byval message as string) as string return "hello world" & message end function
end class host 程序代碼 imports system.runtime.remoting.channels imports system.runtime.remoting.remotingconfiguration public class hostclass host public shared sub main()sub main() dim channel as new http.httpserverchannel(6363) channelservices.registerchannel(channel) registerwellknownservicetype(gettype(objectlib.simpleobject), "simpleobject", runtime.remoting.wellknownobjectmode.singlecall) console.writeline("started ok") console.readline() end sub end class
下面討論幾種調用方式
1.可客戶端不支持或者沒有安裝.net framework 的情況。
本質上remoting 服務端和客戶端走的是soap協議,對于簡單的方法。只要客戶端能支持soap就可以了。微軟提供了一個soaptoolkit ,比如在vb6 中調用我的remoting 服務。 dim o as new soapclient30 o.mssoapinit "http://server:6363/simpleobject?wsdl" msgbox o.helloworld("montaque")
2. 在vb.net 中調用remoting 服務。通過bindingtomoniker
dim o as object = system.runtime.interopservices.marshal.bindtomoniker("soap:wsdl=http://localhost:6363/simpleobject?wsdl") msgbox(o.helloworld("asdf")) 當然要設置option explicit off