C # Build an XmlRpc server without IIS

Source: Internet
Author: User

Prepare to use CookComputing. XmlRpcServerV2 3.0.0 to build the XmlRpc server. Create a console project and add a reference to CookComputing. XmlRpcServerV2 3.0.0 to the project. You can use nuget for installation. PM> Install-Package xmlrpcnetPM> Install-Package xmlrpcnet-server write service I wrote a very simple service here. The Code is as follows: public class SimpleService: xmlRpcListenerService {[XmlRpcMethod] public int Add (int a, int B) {return a + B ;}} compile the Service Host code, that is, XmlRpc service code. Here we use the HttpListener class to process requests from the XmlRpc client. HttpListener uses asynchronous processing. The Code is as follows: class Program {private static XmlRpcListenerService _ svc = new SimpleService (); static void Main (string [] Args) {HttpListener listener = new HttpListener (); listener. prefixes. add ("http: // 127.0.0.1: 11000/"); listener. start (); listener. beginGetContext (new AsyncCallback (ProcessRequest), listener); Console. readLine ();} static void ProcessRequest (IAsyncResult result) {HttpListener listener = result. asyncState as HttpListener; // end Asynchronous Operation HttpListenerContext context = listener. endGetContext (result); // weight Start asynchronous request processing listener. beginGetContext (new AsyncCallback (ProcessRequest), listener); try {Console. writeLine ("From:" + context. request. userHostAddress); // process the request _ svc. processRequest (context);} catch (Exception ex) {Console. writeLine (ex. after the program is started, open the browser to access: http: // 127.0.0.1: 11000/. The following page is displayed. Now you can call the XmlRpc service. XmlRpc Service

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.