我看了几个Remoting的范例,自己做总是做不成功,有个问题一直想不明白,
假设有个dll我想把他做成远程访问的组件 ,但是当我客户端调用该组件的时候,在实例化时总是说我没有申明,在编译客户端的时候还要加入该组件才行,那我怎么知道我客户端运行时到底调用了服务器端的远程组件没有啊,望高手指点迷津远程组件:remote.dll
客户端:
Dim channel As New HttpChannel(0)
ChannelServices.RegisterChannel(channel) ' Registers the remote class. (This could be done with a
' configuration file instead of a direct call.)
RemotingConfiguration.RegisterWellKnownClientType(Type.GetType("ServiceClass, remote"), "http://localhost:8080/object1uri") ' Instead of creating a new object, this obtains a reference
' to the server's single instance of the ServiceClass object.
Dim object1 As ServiceClass = New ServiceClass() Try
Console.WriteLine("ServerTime: " & object1.GetServerTime())
Catch ex As Exception
Console.WriteLine("Exception of type: " & ex.GetType.ToString & " occurred.")
Console.WriteLine("Details: " & ex.Message)
End Try
这是微软的一个例子:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconremotingexamples.asp就是当客户端实例化这个Dim object1 As ServiceClass = New ServiceClass()
的时候,会出现没有申明,要引用remote.dll,难道编译客户端的时候一定要引用远程的dll吗,
假设有个dll我想把他做成远程访问的组件 ,但是当我客户端调用该组件的时候,在实例化时总是说我没有申明,在编译客户端的时候还要加入该组件才行,那我怎么知道我客户端运行时到底调用了服务器端的远程组件没有啊,望高手指点迷津远程组件:remote.dll
客户端:
Dim channel As New HttpChannel(0)
ChannelServices.RegisterChannel(channel) ' Registers the remote class. (This could be done with a
' configuration file instead of a direct call.)
RemotingConfiguration.RegisterWellKnownClientType(Type.GetType("ServiceClass, remote"), "http://localhost:8080/object1uri") ' Instead of creating a new object, this obtains a reference
' to the server's single instance of the ServiceClass object.
Dim object1 As ServiceClass = New ServiceClass() Try
Console.WriteLine("ServerTime: " & object1.GetServerTime())
Catch ex As Exception
Console.WriteLine("Exception of type: " & ex.GetType.ToString & " occurred.")
Console.WriteLine("Details: " & ex.Message)
End Try
这是微软的一个例子:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconremotingexamples.asp就是当客户端实例化这个Dim object1 As ServiceClass = New ServiceClass()
的时候,会出现没有申明,要引用remote.dll,难道编译客户端的时候一定要引用远程的dll吗,
解决方案 »
- 无限级分类管理有否好的建议
- .cs文件如何編譯成bin文件
- SQL数据返回值以及在显示数据内容如何取得值!!------在线等!!
- 请教关于一个网页包含另一个网页的问题。
- DataGrid数据绑定能否在下面求总计?1分也没有啦:(
- js传控件名(在线)
- javascript前台取值
- 怎么给DataGrid中模板列的EditItemTemplate里面的对象传递数据?
- CrystalReportViewer的问题
- 快过年,散点分,顺便给大家拜个早年!
- 那位能让datagrid中的pagersytle中参数mode在表的下面去掉,不留任何东西。
- 在HTML页面中加如IFRAME镶入ASPX留言本页面后,页面能正常显示,但留言链接无法打开,提示错误!!急!!!
假设我要远程访问的组件要实现事务控制,那么我可以让这个组件从servicecomponent继承,在COM+环境中运行,而我们又知道要是实现引用传递的远程组件,必须从MarshalByRefObject
继承,那么我怎样能做到访问远程机器上的COM+组件呢?
using System;
using System.Runtime.Remoting.Channels; //To support and handle Channel and channel sinks
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Http; //For HTTP channel
using System.IO;namespace ServerApp
{ public class RemotingServer
{
public RemotingServer()
{
//
// TODO: Add constructor logic here
//
}
}
//Service class
public class Service: MarshalByRefObject
{
public void WriteMessage (int num1,int num2)
{
SyncLock Me;
Console.WriteLine (Math.Max(num1,num2));
End SyncLock;
}
}
//Server Class
public class Server
{
public static void Main ()
{
HttpChannel channel = new HttpChannel(8001); //Create a new channel
ChannelServices.RegisterChannel (channel); //Register channel
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Service),"Service",WellKnownObjectMode.Singleton);
Console.WriteLine ("Server ON at port number:8001");
Console.WriteLine ("Please press enter to stop the server.");
Console.ReadLine ();
}
}}
//说明:先建好服务器端,再用命令:
//soapsuds -url:http://< Machine Name where service is running>:8001/Service?WSDL -oa:Server.dll
//生成客户端引用的DLL
//建立客户端,即可
client
using System;
using System.Runtime.Remoting.Channels; //To support and handle Channel and channel sinks
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Http; //For HTTP channel
using System.IO;
using ServerApp;
namespace RemotingApp
{ public class ClientApp
{
public ClientApp()
{ } public static void Main (string[] args)
{
HttpChannel channel = new HttpChannel (8002); //Create a new channel
ChannelServices.RegisterChannel (channel); //Register the channel
//Create Service class object
Service svc = (Service) Activator.GetObject (typeof (Service),"http://cap36:8001/Service"); //Localhost can be replaced by
//Pass Message
svc.WriteMessage (10,20);
} }
}