您的位置:首页 > 编程语言 > C#

C# 用Remote技术实现简单SOAP通讯

2014-04-16 08:41 274 查看
我现在想用C#做个SOAP的通信,主要功能是,

1、在internet上把一个服务器上的文件送到另一台服务器上

2、在接受完成后返回一个成功的信号。

第一个是DLL文件;

lizi1.cs

using System;

public interface ISimpleObject{
String ToUpper(String inString);
}


第二个是服务器文件;

lizi2.cs

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class SimpleObject:MarshalByRefObject,ISimpleObject{
public String ToUpper(String inString){
Console.WriteLine("Send String is "+inString);
return(inString.ToUpper());
}
}
class lizi2{
public static void Main(){
HttpChannel hchan = new HttpChannel(154);
ChannelServices.RegisterChannel(hchan);
Type SimpleObjectType = Type.GetType("SimpleObject");

RemotingConfiguration.RegisterWellKnownServiceType(SimpleObjectType,"SOEndPoint",WellKnownObjectMode.Singleton);
Console.WriteLine("press enter to halt server");
Console.ReadLine();
}
}


第三个是客户端文件

lizi3.cs

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

class lizi3{
public static void Main(){
HttpChannel hchan = new HttpChannel(0);
ChannelServices.RegisterChannel(hchan);
Object remoteObject = RemotingServices.Connect(typeof(ISimpleObject),"http://localhost:154/SOEndPoint");

ISimpleObject so = remoteObject as ISimpleObject;

Console.WriteLine(so.ToUpper("make this uppercase"));
}
}


在编译的时候需要先把lizi1编译成DLL文件如:csc /t:libraty lizi1.cs

然后编译服务器端成EXE如:csc /r:System.Runtime.Remoting.dll /r:lizi1.dll lizi2.cs

最后编译客户端成EXE如:csc /r:System.Runtime.Remoting.dll /r:lizi1.dll lizi3.cs

这样就可以跑了,而且是通过HTTP将SOAP封装的消息送到服务器端,最后得到返回。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: