问题描述
生成远程对象的接口:namespaceRemottingObjectInterface{publicinterfaceIHello{stringGreeting(stringname);}}远程对象:namespaceRemottingObject{publicclassHello:System.MarshalByRefObject,IHello{publicHello(){Console.WriteLine("Hello'sConstructoriscalled!");}~Hello(){Console.WriteLine("Hello'sDestructoriscalled!");}publicstringGreeting(stringname){Console.WriteLine("Greetingcalled!");return"Hello"+name;}}}客户端调用代码:namespaceTestClient{classProgram{staticvoidMain(string[]args){//TcpClientChannelchannel=newTcpClientChannel();//ChannelServices.RegisterChannel(channel,false);//IHellohello=(IHello)Activator.GetObject(typeof(RemottingObjectInterface.IHello),"tcp://localhost:8089/Hi");RemotingConfiguration.Configure("TestClient.exe.config");IHellohello=(IHello)Activator.GetObject(typeof(RemottingObjectInterface.IHello),"tcp://localhost:8089/Hi");Console.WriteLine(hello.Greeting("-Guoxc"));}}}服务器端配置文件:<?xmlversion="1.0"encoding="utf-8"?><configuration><application><service><channels><channelref="tcp"port="8089"/></channels><wellknowntype="RemottingObject.Hello,RemottingObject"mode="SingleCall"ObjectUri="Hi"></wellknown></service></application></configuration>客户端配置文件:<?xmlversion="1.0"encoding="utf-8"?><configuration><system.runtime.remoting><application><client><wellknowntype="RemottingObjectInterface.IHello,RemottingObjectInterface"url="tcp://localhost:8089/Hi"/></client></application></system.runtime.remoting></configuration>********问题******************安装并启动了Windows服务承载远程对象“Hello”,执行客户程序抛出异常,异常信息为:【由于目标机器积极拒绝,无法连接。127.0.0.1:8089】问题出在哪里,请前辈们解决,不胜感激!!******************************************************
解决方案
解决方案二:
服务端配置system.runtime.remoting><applicationname="Service"><service><wellknowntype="RemottingObject.Hello,RemottingObject"mode="SingleCall"ObjectUri="Hi"></wellknown></service><channels><channelref="tcp"port="8089"><serverProviders><providerref="wsdl"/><formatterref="binary"typeFilterLevel="Full"/></serverProviders><clientProviders><formatterref="binary"/></clientProviders></channel></channels></application><customErrorsmode="Off"/></system.runtime.remoting>