zoukankan      html  css  js  c++  java
  • c# 创建 XMLRPC服务

    1、下载XML-PRC for .net 包,工程中引用CookComputing.XmlRpcV2.dll
    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);
            }
    
        }
    }




  • 相关阅读:
    PowerDesigner16 破解
    双向链表的实现与操作(C语言实现)
    【HDOJ 2063】过山车
    gcc 源代码分析-前端篇2
    Android4.0.4-在build.prop中添加属性的方法【转】
    安卓系统手动添加虚拟按键教程【转】
    android 添加新的键值,自定义按键-2【转】
    android 添加新的键值,自定义按键【转】
    Android下添加新的自定义键值和按键处理流程【转】
    android监听虚拟按键的显示与隐藏【转】
  • 原文地址:https://www.cnblogs.com/whisht/p/3085081.html
Copyright © 2011-2022 走看看