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