c# 创建 XML-RPC服务
2012-08-10 15:44
417 查看
1、下载XML-PRC for .net 包,工程中引用CookComputing.XmlRpcV2.dll
2、接口文件
3、创建启动和关闭RPC服务
2、接口文件
using System; using System.Collections.Generic; using System.Windows.Forms; using SMSServer; using CookComputing.XmlRpc; namespace SMSServer.Service { #region 测试结构体 //忽略某字段 //public struct SampleStruct //{ // public string title; // public string link; // [XmlRpcMissingMapping(MappingAction.Ignore)] // public string description; //} //某字段必填 //[XmlRpcMissingMapping(MappingAction.Ignore)] //public struct SampleStruct //{ // [XmlRpcMissingMapping(MappingAction.Error)] // public string title; // [XmlRpcMissingMapping(MappingAction.Error)] // public string link; // public string description; //} public struct sTest { public int a; public string b; public DateTime c; [XmlRpcMissingMapping(MappingAction.Ignore)] //public char d; public byte[] e; public bool f; } #endregion public interface ISMSService { [XmlRpcMethod("SMSServer.Lee")] string Lee(string str); } public class SMSService : MarshalByRefObject, ISMSService { public string Lee(string str) { return DateTime.Now.ToString() + ":" + str; } } }
3、创建启动和关闭RPC服务
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Http; using System.Threading; using System.IO; using System.Runtime.InteropServices; using CookComputing.XmlRpc; using SMSServer.Service; namespace SMSServer { public partial class FrmMain : Form { public HttpChannel channel; public FrmMain() { InitializeComponent(); } private void FrmMain_Load(object sender, EventArgs e) { //button1.Visible = false; IDictionary props = new Hashtable(); props["name"] = "SMSHttpChannel"; props["port"] = 5678; channel = new HttpChannel( props, null, new XmlRpcServerFormatterSinkProvider() ); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType( typeof(SMSService), "sms.rem", WellKnownObjectMode.Singleton); } private void FrmMain_FormClosed(object sender, FormClosedEventArgs e) { ChannelServices.UnregisterChannel(channel); } } }
相关文章推荐
- c# 创建 XML-RPC服务
- 用C#创建简单的windows服务程序
- [C#]实现对XML文件的基本操作(创建xml文件,增、删、改、查 xml节点信息)
- XML-RPC 实现C++和C#交互
- C# 创建XML并输出XML
- C#之创建Xml
- C# windows服务:创建Windows服务(Windows Services)的一般步骤
- C# 创建window服务
- C#创建Windows服务程序
- c#对xml的创建、查询
- C# 如何创建一个xml文件?并写入指定内容?
- c# 创建xml
- C# 创建 Windows 服务
- C# 创建,读取,写入XML文件
- C#创建/写XML
- C# 实现对XML文件的基本操作(创建xml文件,增、删、改、查 xml节点信息)
- 用C#创建XML[简单代码]
- C#创建windows服务搭配定时器Timer使用实例(用代码做,截图版)
- 【C#】XML的创建与读取