急(分不够的话可以再加):VC++.NET建的 ASP.NET Web服务工程调用Remoting服务失败
问题说明:VC++.NET建的 ASP.NET Web服务工程调用Remoting服务失败
VC++.NET建的Asp.NET Web服务工程 不能 调用成功(其他工程都能调用成功),主要代码如下(与Windows窗体应用程序代码相同):
void test()
{
(此处设置一个端点) invoke();
}
void invoke()
{
try
{
#ifdef GetObject
#undef GetObject
#endif
(此处设置一个端点) RemotingServer::Class1 * b = (RemotingServer::Class1) Activator::GetObject(__typeof(RemotingServer::Class1),"http://172.21.14.61:8883/Class1");
String * s = b->sayHello(); }
catch(ArgumentNullException * ae) //type 或 url 为空引用
{ }
catch(RemotingException * re) //type 未通过引用或某个接口封送处理
{ }
}
出现的问题:当你测试调试Web服务的时候,程序运行到invoke()那个,然后继续跟踪(F11)就出错,Web页面出现“服务器内部错误”。如果把 远程调用语句注释掉,程序就可以正常的运行。
编译能通过。但是调试的时候不能进入函数invoke里面,很奇怪。请高手指点。
我的QQ:71727288,加我的话附加信息填:VC.NET Remoting.
但是同样的代码同样的软件环境下,其他工程都能够调用:
远程机器上:
Remoting dll 主要代码(C#):
namespace RemotingServer
{
public class Class1 : System.MarshalByRefObject
{
public Class1()
{ }
public String sayHello()
{ return "Hello world!"; }
}
}
Windows服务工程的主要代码(C#):
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.ComponentModel.Container components = null;
public Service1()
{
InitializeComponent();
}
// 进程的主入口点
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
TcpChannel MyChannel = new TcpChannel(8881);
ChannelServices.RegisterChannel(MyChannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingServer.Class1),"Class1",WellKnownObjectMode.SingleCall);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{ components.Dispose(); }
}
base.Dispose( disposing );
}
protected override void OnStart(string[] args)
{ }
protected override void OnStop()
{ }
}
调用端:
C#建的 所有工程都能够调用成功,主要代码如下;
try
{
RemotingServer.Class1 b = (RemotingServer.Class1) Activator.GetObject(typeof(RemotingServer.Class1),"http://172.21.14.61:8883/Class1");
string s = b.sayHello();
}
catch(ArgumentNullException ae) //type 或 url 为空引用
{ }
catch(RemotingException re) //type 未通过引用或某个接口封送处理
{ }
VC++.NET建的 Windows窗体应用程序能调用成功,主要代码如下:
try
{
#ifdef GetObject
#undef GetObject
#endif
RemotingServer::Class1 * b = (RemotingServer::Class1) Activator::GetObject(__typeof(RemotingServer::Class1),"http://172.21.14.61:8883/Class1");
String * s = b->sayHello(); }
catch(ArgumentNullException * ae) //type 或 url 为空引用
{ }
catch(RemotingException * re) //type 未通过引用或某个接口封送处理
{ }