c# 创建 XML-RPC客户端和博客通信

c# 创建 XML-RPC客户端和博客通信  可以创建博客文章删除等 Wordpress就是最好的李子

1、下载XML-PRC for .net 包,工程中引用CookComputing.XmlRpcV2.dll
2、接口文件

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Windows.Forms;  
  4.   
  5. using SMSServer;  
  6. using CookComputing.XmlRpc;  
  7.   
  8. namespace SMSServer.Service  
  9. {  
  10.     #region 测试结构体  
  11.   
  12.     //忽略某字段  
  13.     //public struct SampleStruct  
  14.     //{  
  15.     //    public string title;  
  16.     //    public string link;  
  17.     //    [XmlRpcMissingMapping(MappingAction.Ignore)]  
  18.     //    public string description;  
  19.     //}   
  20.   
  21.   
  22.     //某字段必填  
  23.     //[XmlRpcMissingMapping(MappingAction.Ignore)]  
  24.     //public struct SampleStruct  
  25.     //{  
  26.     //    [XmlRpcMissingMapping(MappingAction.Error)]  
  27.     //    public string title;  
  28.     //    [XmlRpcMissingMapping(MappingAction.Error)]  
  29.     //    public string link;  
  30.     //    public string description;  
  31.     //}   
  32.   
  33.     public struct sTest  
  34.     {  
  35.         public int a;  
  36.         public string b;  
  37.         public DateTime c;  
  38.         [XmlRpcMissingMapping(MappingAction.Ignore)]  
  39.         //public char d;  
  40.         public byte[] e;  
  41.         public bool f;  
  42.     }  
  43.     #endregion  
  44.   
  45.   
  46.     public interface ISMSService  
  47.     {  
  48.         [XmlRpcMethod("SMSServer.Lee")]  
  49.         string Lee(string str);  
  50.     }  
  51.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  52.     public class SMSService : MarshalByRefObject, ISMSService  
  53.     {  
  54.         public string Lee(string str)  
  55.         {  
  56.             return DateTime.Now.ToString() + ":" + str;  
  57.         }  
  58.     }  
  59. }  
  60. 3、创建启动和关闭RPC服务
  1. using System;  
  2. using System.Collections;  
  3. using System.Collections.Generic;  
  4. using System.ComponentModel;  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Runtime.Remoting;  
  10. using System.Runtime.Remoting.Channels;  
  11. using System.Runtime.Remoting.Channels.Http;  
  12. using System.Threading;  
  13. using System.IO;  
  14. using System.Runtime.InteropServices;  
  15.   
  16. using CookComputing.XmlRpc;  
  17. using SMSServer.Service;  
  18.   
  19. namespace SMSServer  
  20. {  
  21.     public partial class FrmMain : Form  
  22.     {  
  23.   
  24.         public HttpChannel channel;  
  25.   
  26.           
  27.   
  28.         public FrmMain()  
  29.         {  
  30.             InitializeComponent();  
  31.         }  
  32.   
  33.           
  34.   
  35.         private void FrmMain_Load(object sender, EventArgs e)  
  36.         {  
  37.             //button1.Visible = false;  
  38.             IDictionary props = new Hashtable();  
  39.             props["name"] = "SMSHttpChannel";  
  40.             props["port"] = 5678;  
  41.             channel = new HttpChannel(  
  42.                props,  
  43.                null,  
  44.                new XmlRpcServerFormatterSinkProvider()  
  45.             );  
  46.             ChannelServices.RegisterChannel(channel, false);  
  47.             RemotingConfiguration.RegisterWellKnownServiceType(  
  48.                  typeof(SMSService),  
  49.                  "sms.rem",  
  50.                  WellKnownObjectMode.Singleton);  
  51.         }  
  52.   
  53.         private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)  
  54.         {  
  55.             ChannelServices.UnregisterChannel(channel);  
  56.         }  
  57.   
  58.     }  
  59. }  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     

转载于:https://www.cnblogs.com/ftchen/p/4963104.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值