पहले उदाहरण में बताया गया के लिए एक प्रमाण पत्र को कॉन्फ़िगर करने की आवश्यकता होगी, मैं इस समस्या पर उसकी मदद के लिए और XMLRPC के विकास के लिए दिल से चार्ल्स कुक का शुक्रिया अदा करना चाहते हैं। नेट।
दूसरा, इस नमूने XMLRPC.NET StateNameServer नमूने पर डाउनलोड के लिए उपलब्ध आधारित है: http://xml-rpc.net/download.html
तो यहाँ
समाधान है:
1. उत्पन्न या एक [स्व-हस्ताक्षरित] मिल प्रमाण पत्र (उदाहरण के लिए makecert.exe का उपयोग कर)
2. अपने सर्वर विन्यास के लिए इस प्रमाणपत्र जोड़ें और बंदरगाह आप (इस मामले 5678 में) अपने XMLRPC.NET सर्वर के साथ उपयोग करना चाहते हैं का उपयोग कर httpcf निर्दिष्ट
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using CookComputing.XmlRpc;
using System.Net;
using System.IO;
public class _
{
static void Main(string[] args)
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("https://127.0.0.1:5678/");
listener.Start();
while (true)
{
HttpListenerContext context = listener.GetContext();
ListenerService svc = new StateNameService();
svc.ProcessRequest(context);
}
Console.WriteLine("Press <ENTER> to shutdown");
Console.ReadLine();
}
}
public class StateNameService : ListenerService
{
[XmlRpcMethod("examples.getStateName")]
public string GetStateName(int stateNumber)
{
if (stateNumber < 1 || stateNumber > m_stateNames.Length)
throw new XmlRpcFaultException(1, "Invalid state number");
return m_stateNames[stateNumber - 1];
}
string[] m_stateNames
= { "Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Lousiana", "Maine", "Maryland", "Massachusetts",
"Michigan", "Minnesota", "Mississipi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",
"New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
"Oregon", "Pennsylviania", "Rhose Island", "South Carolina",
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming" };
}
public abstract class ListenerService : XmlRpcHttpServerProtocol
{
public virtual void ProcessRequest(HttpListenerContext RequestContext)
{
try
{
IHttpRequest req = new ListenerRequest(RequestContext.Request);
IHttpResponse resp = new ListenerResponse(RequestContext.Response);
HandleHttpRequest(req, resp);
RequestContext.Response.OutputStream.Close();
}
catch (Exception ex)
{
// "Internal server error"
RequestContext.Response.StatusCode = 500;
RequestContext.Response.StatusDescription = ex.Message;
}
}
}
public class ListenerRequest : CookComputing.XmlRpc.IHttpRequest
{
public ListenerRequest(HttpListenerRequest request)
{
this.request = request;
}
public Stream InputStream
{
get { return request.InputStream; }
}
public string HttpMethod
{
get { return request.HttpMethod; }
}
private HttpListenerRequest request;
}
public class ListenerResponse : CookComputing.XmlRpc.IHttpResponse
{
public ListenerResponse(HttpListenerResponse response)
{
this.response = response;
}
string IHttpResponse.ContentType
{
get { return response.ContentType; }
set { response.ContentType = value; }
}
TextWriter IHttpResponse.Output
{
get { return new StreamWriter(response.OutputStream); }
}
Stream IHttpResponse.OutputStream
{
get { return response.OutputStream; }
}
int IHttpResponse.StatusCode
{
get { return response.StatusCode; }
set { response.StatusCode = value; }
}
string IHttpResponse.StatusDescription
{
get { return response.StatusDescription; }
set { response.StatusDescription = value; }
}
private HttpListenerResponse response;
}
public class StateNameServer : MarshalByRefObject, IStateName
{
public string GetStateName(int stateNumber)
{
if (stateNumber < 1 || stateNumber > m_stateNames.Length)
throw new XmlRpcFaultException(1, "Invalid state number");
return m_stateNames[stateNumber-1];
}
public string GetStateNames(StateStructRequest request)
{
if (request.state1 < 1 || request.state1 > m_stateNames.Length)
throw new XmlRpcFaultException(1, "State number 1 invalid");
if (request.state2 < 1 || request.state2 > m_stateNames.Length)
throw new XmlRpcFaultException(1, "State number 1 invalid");
if (request.state3 < 1 || request.state3 > m_stateNames.Length)
throw new XmlRpcFaultException(1, "State number 1 invalid");
string ret = m_stateNames[request.state1-1] + " "
+ m_stateNames[request.state2-1] + " "
+ m_stateNames[request.state3-1];
return ret;
}
string[] m_stateNames
= { "Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Lousiana", "Maine", "Maryland", "Massachusetts",
"Michigan", "Minnesota", "Mississipi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",
"New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma",
"Oregon", "Pennsylviania", "Rhose Island", "South Carolina",
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming" };
}
4. का उपयोग कर अपने XMLRPC.NET ग्राहक को लागू करें: g.exe या HttpSysConfig की तरह एक और उपकरण (ओपन सोर्स)
3. निम्नलिखित कोड का उपयोग कर अपने XMLRPC.NET सर्वर को लागू करें कोड निम्नलिखित
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using CookComputing.XmlRpc;
using System.Net;
using System.Security.Cryptography.X509Certificates;
class _
{
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy() { }
public bool CheckValidationResult(ServicePoint sp,
X509Certificate cert,
WebRequest req,
int problem)
{
return true;
}
}
static void Main(string[] args)
{
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
XmlRpcClientProtocol cp = (XmlRpcClientProtocol)proxy;
cp.Url = "https://127.0.0.1:5678/";
cp.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate(@"C:\path\to\your\certificate\file\my.cer"));
cp.KeepAlive = false;
//cp.Expect100Continue = false;
//cp.NonStandard = XmlRpcNonStandard.All;
string stateName = ((IStateName)cp).GetStateName(13);
}
}
बेशक
(कोड को भी एक नया X509 क्लाइंट प्रमाणपत्र बनाता है), मैं यहाँ नहीं देते इंटरफेस कार्यान्वयन सर्वरस्टेटनाम के लिए प्रविष्टि लेकिन आप इसे शीर्ष पर डाउनलोड लिंक का उपयोग करके नमूना फ़ाइलों में पाएंगे।
टिप्पणी:
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy()
; सर्वर कार्यान्वयन को आपके द्वारा जेनरेट किए गए स्वयं-हस्ताक्षरित प्रमाणपत्र को स्वीकार करने की अनुमति देगा। मुझे लगता है कि प्रमाणन प्राधिकरणों द्वारा जारी प्रमाणपत्रों के साथ यह आवश्यक नहीं है।
यदि आपको कुछ भी मिल सकता है जिसे सुधार किया जा सकता है और गलत है तो इसकी बहुत सराहना की जाएगी।
परीक्षण के बाद, मैं पुष्टि कर सकता हूं कि कार्यान्वयन दो अलग-अलग विंडोज मशीनों पर काम करता है। – virrea