分布式开发的问题

jiagun4 2005-12-21 12:23:37
ChannelServices.RegisterChannel(new TcpClientChannel());
Hello obj=(Hello)Activator.GetObject(typeof

(Hello),"tcp://127.0.0.1:8086/hi");
for(int i=0;i<5;i++)
{
Console.WriteLine(obj.getint(3));
}
客户端代码。。客户端程序无法运行。错误在Hello和Obj上
TcpServerChannel chan=new TcpServerChannel(8086);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType(typeof

(Hello),"hi",WellKnownObjectMode.SingleCall);
System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
服务器代码。
类文件已经写了。
究竟是怎么回事??????是不是哪里少写了一句代码??????
...全文
166 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjyong0123 2005-12-23
  • 打赏
  • 举报
回复
动态访问web service,参考一下:
string StrURL = @"http://localhost/MyWebService/Service1.asmx";//web service 的URL
string StrNameSpace = @"MyWebService";//命名空间
string StrClassName = @"Service1";//类名
string StrValidMethod = "ValidUser";//web service 中的方法
string name = "sa"; //调用时传递的参数
string password = "123";//调用时传递的参数
string StrMethodName = "NiHao";//web service 中的方法
//object ObjArgs =

System.Net.WebClient WC = new System.Net.WebClient();
System.IO.Stream stream = WC.OpenRead(StrURL + "?WSDL");
ServiceDescription SD = ServiceDescription.Read(stream);
ServiceDescriptionImporter SDI = new ServiceDescriptionImporter();
SDI.AddServiceDescription(SD,"","");
CodeNamespace CN = new CodeNamespace(StrNameSpace);
CodeCompileUnit CCU = new CodeCompileUnit();
CCU.Namespaces.Add(CN);
SDI.Import(CN,CCU);

CSharpCodeProvider CSCP = new CSharpCodeProvider();
ICodeCompiler ICC = CSCP.CreateCompiler();
CompilerParameters CP = new CompilerParameters();
CP.GenerateExecutable = false;
CP.GenerateInMemory = true;
CP.ReferencedAssemblies.Add("System.dll");
CP.ReferencedAssemblies.Add("System.Xml.dll");
CP.ReferencedAssemblies.Add("System.Web.Services.dll");
CP.ReferencedAssemblies.Add("System.Data.dll");

CompilerResults CR = ICC.CompileAssemblyFromDom(CP,CCU);
if(CR.Errors.HasErrors == true)
{
StringBuilder SB = new StringBuilder();
foreach(CompilerError CE in CR.Errors)
{
SB.Append(CE.ToString());
SB.Append(System.Environment.NewLine);
}
throw new Exception(SB.ToString());
}
Assembly assembly = CR.CompiledAssembly;
Type type = assembly.GetType(StrNameSpace + "." + StrClassName,true,true);
object obj = Activator.CreateInstance(type);
MethodInfo MI = type.GetMethod(StrValidMethod);
bool tempBool = (bool)MI.Invoke(obj,new string[]{name,password});
if(tempBool)
{
string ddd = "";
}
else
{
string dddd = "";
}
MI = type.GetMethod(StrMethodName);
object returnVal = MI.Invoke(obj,new string[]{"zhang"});

string sss = (string)returnVal;
Response.Write("<script>alert(''"+sss+");</script>");
string dd = "";

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧