Remoting 找不到请求的服务
c#高级编程书上的例子:
服务器端:
HelloServer:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteHello;
namespace HelloWerver
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
HelloServer.ShowChannelProperties(channel);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);//把知名的远程对象类型注册为RemotingServices
System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
//channel.ChannelData
}
}
}
RemoteHello.dll:
using System;
using System.Collections.Generic;
using System.Text;
namespace RemoteHello
{
public class Hello:System.MarshalByRefObject
{
public Hello()
{
Console.WriteLine("Constructor called");
}
~Hello()
{
Console.WriteLine("Destructor called");
}
public string Greeting(string name)
{
Console.WriteLine("Greeting called");
return "Hello," + name;
}
}
}
客户端:HelloClient2
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using RemoteHello;
namespace HelloClient2
{
class Program
{
static void Main(string[] args)
{
//object[] attrs ={ new UrlAttribute("tcp://localhost:8086/HelloServer") };
//ObjectHandle handle = Activator.CreateInstance("RemoteHello", "RemoteHello.Hello", attrs);
//if (handle == null)
//{
// Console.WriteLine("could not locate server");
// return;
//}
RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer");
Hello obj = new Hello();//(Hello)handle.Unwrap();
Console.WriteLine(obj.Greeting("Christian"));
Console.ReadLine();
}
}
}
客户端运行到 RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer");
出现异常提示:找不到指定服务。
服务器端:
HelloServer:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteHello;
namespace HelloWerver
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
HelloServer.ShowChannelProperties(channel);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);//把知名的远程对象类型注册为RemotingServices
System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
//channel.ChannelData
}
}
}
RemoteHello.dll:
using System;
using System.Collections.Generic;
using System.Text;
namespace RemoteHello
{
public class Hello:System.MarshalByRefObject
{
public Hello()
{
Console.WriteLine("Constructor called");
}
~Hello()
{
Console.WriteLine("Destructor called");
}
public string Greeting(string name)
{
Console.WriteLine("Greeting called");
return "Hello," + name;
}
}
}
客户端:HelloClient2
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using RemoteHello;
namespace HelloClient2
{
class Program
{
static void Main(string[] args)
{
//object[] attrs ={ new UrlAttribute("tcp://localhost:8086/HelloServer") };
//ObjectHandle handle = Activator.CreateInstance("RemoteHello", "RemoteHello.Hello", attrs);
//if (handle == null)
//{
// Console.WriteLine("could not locate server");
// return;
//}
RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer");
Hello obj = new Hello();//(Hello)handle.Unwrap();
Console.WriteLine(obj.Greeting("Christian"));
Console.ReadLine();
}
}
}
客户端运行到 RemotingConfiguration.RegisterActivatedClientType(typeof(Hello), "tcp://localhost:8086/HelloServer");
出现异常提示:找不到指定服务。
...全文
相关推荐
flex的rpc错误整理
flex的rpc错误整理,多种错误整理,很实用
Ajax、DWR开发文档
AJAX\DWR开发文档,帮助你快速开发ajax\dwr,实现局部刷新
DWR学习笔记
DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站。它可以允许在浏览器里的代码使用运行在WEB服务器上的JAVA函数,就像它就在浏览器里一样。
DWR的相关配置
自己总结的DWR2的相关配置信息、相关注意事项。
Flex与Java通信
有HelloWorld,Flex和Java之间的通信,BlazeDS需要下载,按上面说明即可


