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