本文整理汇总了C#中Nwc.XmlRpc.XmlRpcResponse.SetFault方法的典型用法代码示例。如果您正苦于以下问题:C# XmlRpcResponse.SetFault方法的具体用法?C# XmlRpcResponse.SetFault怎么用?C# XmlRpcResponse.SetFault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nwc.XmlRpc.XmlRpcResponse
的用法示例。
在下文中一共展示了XmlRpcResponse.SetFault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
/// <summary>Handle an HTTP request containing an XML-RPC request.</summary>
/// <remarks>This method deserializes the XML-RPC request, invokes the
/// described method, serializes the response (or fault) and sends the XML-RPC response
/// back as a valid HTTP page.
/// </remarks>
/// <param name="httpReq"><c>SimpleHttpRequest</c> containing the request.</param>
public void Respond(SimpleHttpRequest httpReq)
{
XmlRpcRequest xmlRpcReq = (XmlRpcRequest)_deserializer.Deserialize(httpReq.Input);
XmlRpcResponse xmlRpcResp = new XmlRpcResponse();
try
{
xmlRpcResp.Value = _server.Invoke(xmlRpcReq);
}
catch (XmlRpcException e)
{
xmlRpcResp.SetFault(e.FaultCode, e.FaultString);
}
catch (Exception e2)
{
xmlRpcResp.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
}
if (Logger.Delegate != null)
Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);
XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
httpReq.Output.Flush();
XmlTextWriter xml = new XmlTextWriter(httpReq.Output);
_serializer.Serialize(xml, xmlRpcResp);
xml.Flush();
httpReq.Output.Flush();
}
示例2: GenerateKeyMethod
public XmlRpcResponse GenerateKeyMethod(XmlRpcRequest request, IPEndPoint remoteClient)
{
XmlRpcResponse response = new XmlRpcResponse();
if (request.Params.Count < 2)
{
response.IsFault = true;
response.SetFault(-1, "Invalid parameters");
return response;
}
// Verify the key of who's calling
UUID userID = UUID.Zero;
string authKey = string.Empty;
UUID.TryParse((string)request.Params[0], out userID);
authKey = (string)request.Params[1];
m_log.InfoFormat("[AUTH HANDLER] GenerateKey called with authToken {0}", authKey);
string newKey = string.Empty;
newKey = m_LocalService.GetKey(userID, authKey.ToString());
response.Value = (string)newKey;
return response;
}
示例3: currencyNotify
public XmlRpcResponse currencyNotify(XmlRpcRequest request, IPEndPoint ep)
{
XmlRpcResponse r = new XmlRpcResponse();
try
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable communicationData = (Hashtable)request.Params[1];
#region // Debug
#if DEBUG
m_log.Debug("[OMCURRENCY]: currencyNotify(...)");
foreach (DictionaryEntry requestDatum in requestData)
{
m_log.Debug("[OMCURRENCY]: " + requestDatum.Key.ToString() + " " + (string)requestDatum.Value);
}
foreach (DictionaryEntry communicationDatum in communicationData)
{
m_log.Debug("[OMCURRENCY]: " + communicationDatum.Key.ToString() + " " + (string)communicationDatum.Value);
}
#endif
#endregion
String method = (string)requestData["method"];
requestData.Remove("method");
if (CommunicationHelpers.ValidateRequest(communicationData, requestData, gatewayURL))
{
switch (method)
{
case "notifyDeliverObject": r.Value = deliverObject(requestData);
break;
case "notifyOnObjectPaid": r.Value = onObjectPaid(requestData);
break;
case "notifyLandBuy": r.Value = landBuy(requestData);
break;
case "notifyChangePrimPermission": r.Value = changePrimPermissions(requestData);
break;
case "notifyBalanceUpdate": r.Value = balanceUpdate(requestData);
break;
case "notifyGetVersion": r.Value = GetVersion(requestData);
break;
default: m_log.ErrorFormat("[{0}]: Method {1} is not supported", Name, method);
break;
}
}
else
{
throw new Exception("Hash values do not match");
}
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace);
r.SetFault(1, "Could not parse the requested method");
}
return r;
}
示例4: HandleXmlRpcRequests
//.........这里部分代码省略.........
XmlRpcMethod method;
bool methodWasFound;
bool keepAlive = false;
lock (m_rpcHandlers)
{
methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
if (methodWasFound)
keepAlive = m_rpcHandlersKeepAlive[methodName];
}
if (methodWasFound)
{
xmlRprcRequest.Params.Add(request.Url); // Param[2]
string xff = "X-Forwarded-For";
string xfflower = xff.ToLower();
foreach (string s in request.Headers.AllKeys)
{
if (s != null && s.Equals(xfflower))
{
xff = xfflower;
break;
}
}
xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]
if (gridproxy)
xmlRprcRequest.Params.Add("gridproxy"); // Param[4]
try
{
xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
}
catch(Exception e)
{
string errorMessage
= String.Format(
"Requested method [{0}] from {1} threw exception: {2} {3}",
methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);
m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);
// if the registered XmlRpc method threw an exception, we pass a fault-code along
xmlRpcResponse = new XmlRpcResponse();
// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(-32603, errorMessage);
}
// if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
response.KeepAlive = keepAlive;
}
else
{
xmlRpcResponse = new XmlRpcResponse();
// Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(
XmlRpcErrorCodes.SERVER_ERROR_METHOD,
String.Format("Requested method [{0}] not found", methodName));
}
response.ContentType = "text/xml";
using (MemoryStream outs = new MemoryStream())
using (XmlTextWriter writer = new XmlTextWriter(outs, UTF8NoBOM))
{
writer.Formatting = Formatting.None;
XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
writer.Flush();
outs.Flush();
outs.Position = 0;
using (StreamReader sr = new StreamReader(outs))
{
responseString = sr.ReadToEnd();
}
}
}
else
{
//HandleLLSDRequests(request, response);
response.ContentType = "text/plain";
response.StatusCode = 404;
response.StatusDescription = "Not Found";
response.ProtocolVersion = "HTTP/1.0";
responseString = "Not found";
response.KeepAlive = false;
m_log.ErrorFormat(
"[BASE HTTP SERVER]: Handler not found for http request {0} {1}",
request.HttpMethod, request.Url.PathAndQuery);
}
}
byte[] buffer = Encoding.UTF8.GetBytes(responseString);
response.SendChunked = false;
response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8;
return buffer;
}
示例5: multiCall
public IList multiCall(IList calls)
{
IList responses = new ArrayList();
XmlRpcResponse fault = new XmlRpcResponse();
foreach (IDictionary call in calls)
{
try
{
XmlRpcRequest req = new XmlRpcRequest((String)call[XmlRpcXmlTokens.METHOD_NAME],
(ArrayList)call[XmlRpcXmlTokens.PARAMS]);
Object results = _server.Invoke(req);
IList response = new ArrayList();
response.Add(results);
responses.Add(response);
}
catch (XmlRpcException e)
{
fault.SetFault(e.FaultCode, e.FaultString);
responses.Add(fault.Value);
}
catch (Exception e2)
{
fault.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
responses.Add(fault.Value);
}
}
return responses;
}
示例6: GenericNotify
public XmlRpcResponse GenericNotify(XmlRpcRequest request, IPEndPoint ep)
{
XmlRpcResponse r = new XmlRpcResponse();
try
{
Hashtable requestData = m_communication.ValidateRequest(request);
if (requestData != null)
{
string method = (string)requestData["method"];
switch (method)
{
case "notifyUser": r.Value = UserInteract(requestData);
break;
case "writeLog": r.Value = WriteLog(requestData);
break;
case "notifyIsAlive": r.Value = IsAlive(requestData);
break;
default: m_log.ErrorFormat("[{0}]: Method {1} is not supported.", Name, method);
break;
}
}
else
{
r.SetFault(1, "Could not validate the request");
}
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace);
r.SetFault(1, "Could not parse the requested method");
}
return r;
}
示例7: XmlRpcCommand
public XmlRpcResponse XmlRpcCommand(XmlRpcRequest request, IPEndPoint remoteClient)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
try
{
responseData["Status"] = "Success";
responseData["Value"] = "";
XmlMethodHandler handler = LookupCommand(request.MethodNameObject, request.MethodNameMethod);
if (handler != null)
{
responseData["Value"] = handler(request.Params, remoteClient);
response.Value = responseData;
}
else
{
// Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
response.SetFault(
XmlRpcErrorCodes.SERVER_ERROR_METHOD,
String.Format("Requested method [{0}] not found", request.MethodNameObject + "." + request.MethodNameMethod));
}
}
catch (Exception e)
{
responseData["Status"] = "Failure";
responseData["ErrorDescription"] = e.Message;
response.Value = responseData;
}
return response;
}
示例8: HandleXmlRpcRequests
/// <summary>
/// Try all the registered xmlrpc handlers when an xmlrpc request is received.
/// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
/// </summary>
/// <param name="request"></param>
/// <param name="response"></param>
private void HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
{
Stream requestStream = request.InputStream;
Encoding encoding = Encoding.UTF8;
StreamReader reader = new StreamReader(requestStream, encoding);
string requestBody = reader.ReadToEnd();
reader.Close();
requestStream.Close();
//m_log.Debug(requestBody);
requestBody = requestBody.Replace("<base64></base64>", "");
string responseString = String.Empty;
XmlRpcRequest xmlRprcRequest = null;
try
{
xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
}
catch (XmlException)
{
}
if (xmlRprcRequest != null)
{
string methodName = xmlRprcRequest.MethodName;
if (methodName != null)
{
xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
XmlRpcResponse xmlRpcResponse;
XmlRpcMethod method;
bool methodWasFound;
bool keepAlive = false;
lock (m_rpcHandlers)
{
methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
if (methodWasFound)
keepAlive = m_rpcHandlersKeepAlive[methodName];
}
if (methodWasFound)
{
xmlRprcRequest.Params.Add(request.Url); // Param[2]
string xff = "X-Forwarded-For";
string xfflower = xff.ToLower();
foreach (string s in request.Headers.AllKeys)
{
if (s != null && s.Equals(xfflower))
{
xff = xfflower;
break;
}
}
xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]
try
{
xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
}
catch(Exception e)
{
string errorMessage
= String.Format(
"Requested method [{0}] from {1} threw exception: {2} {3}",
methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);
m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);
// if the registered XmlRpc method threw an exception, we pass a fault-code along
xmlRpcResponse = new XmlRpcResponse();
// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(-32603, errorMessage);
}
// if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
response.KeepAlive = keepAlive;
}
else
{
xmlRpcResponse = new XmlRpcResponse();
// Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(
XmlRpcErrorCodes.SERVER_ERROR_METHOD,
String.Format("Requested method [{0}] not found", methodName));
}
responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
}
else
{
//.........这里部分代码省略.........
示例9: currencyNotify
public XmlRpcResponse currencyNotify(XmlRpcRequest request, IPEndPoint ep)
{
XmlRpcResponse r = new XmlRpcResponse ();
Hashtable requestData = m_communication.ValidateRequest(request);
if(requestData != null) {
string method = (string)requestData["method"];
switch (method)
{
case "notifyDeliverObject": r.Value = deliverObject(requestData);
break;
case "notifyOnObjectPaid": r.Value = onObjectPaid(requestData);
break;
case "notifyLandBuy": r.Value = landBuy(requestData);
break;
case "notifyChangePrimPermission": r.Value = changePrimPermissions(requestData);
break;
case "notifyBalanceUpdate": r.Value = balanceUpdate(requestData);
break;
case "notifyGetVersion": r.Value = GetVersion(requestData);
break;
default: m_log.ErrorFormat("[{0}]: Method {1} is not supported", Name, method);
break;
}
} else {
r.SetFault(-1, "Could not validate the request");
}
return r;
}
示例10: Handle
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
{
XmlRpcRequest xmlRpcRequest = null;
XmlRpcResponse xmlRpcResponse = null;
string requestBody = null;
byte[] response;
Encoding encoding = Encoding.UTF8;
StreamReader streamReader = new StreamReader(request, encoding);
requestBody = streamReader.ReadToEnd();
streamReader.Close();
try
{
xmlRpcRequest = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
}
catch (XmlException e)
{
m_log.ErrorFormat("[XMLRPC STREAM HANDLER]: XmlRpc request failed to deserialize: {0} -> {1}", e, requestBody);
xmlRpcRequest = null;
}
if (xmlRpcRequest != null)
{
string methodName = xmlRpcRequest.MethodName;
if (methodName != null)
{
xmlRpcRequest.Params.Add(httpRequest.RemoteIPEndPoint); // Param[1]
xmlRpcRequest.Params.Add(httpRequest.Url); // Param[2]
xmlRpcRequest.Params.Add(getForwardedFor(httpRequest)); // Param[3]
try
{
xmlRpcResponse = m_xmlrpcMethod(xmlRpcRequest, httpRequest.RemoteIPEndPoint);
}
catch(Exception e)
{
string errorMessage =
String.Format(
"Requested method [{0}] from {1} threw exception: {2} {3}",
methodName, httpRequest.RemoteIPEndPoint.Address, e.Message, e.StackTrace);
m_log.ErrorFormat("[XMLRPC STREAM HANDLER]: {0}", errorMessage);
// if the registered XmlRpc method threw an exception, we pass a fault-code along
xmlRpcResponse = new XmlRpcResponse();
// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(-32603, errorMessage);
}
}
else
{
xmlRpcResponse = new XmlRpcResponse();
// Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(
XmlRpcErrorCodes.SERVER_ERROR_METHOD,
String.Format("Requested method [{0}] not found", methodName));
}
response = Encoding.UTF8.GetBytes(XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse));
httpResponse.ContentType = "text/xml";
}
else
{
response = Encoding.UTF8.GetBytes("Not found");
httpResponse.ContentType = "text/plain";
httpResponse.StatusCode = 404;
httpResponse.StatusDescription = "Not Found";
httpResponse.ProtocolVersion = new System.Version("1.0");
m_log.ErrorFormat(
"[XMLRPC STREAM HANDLER]: Handler not found for http request {0} {1}",
httpRequest.HttpMethod, httpRequest.Url.PathAndQuery);
}
httpResponse.ContentLength64 = response.LongLength;
httpResponse.ContentEncoding = Encoding.UTF8;
httpResponse.SendChunked = false;
return (response);
}
示例11: HandleXmlRpcRequests
/// <summary>
/// Try all the registered xmlrpc handlers when an xmlrpc request is received.
/// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
/// </summary>
/// <param name="request"></param>
/// <param name="response"></param>
private bool HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
{
XmlRpcRequest xmlRprcRequest = null;
string requestBody;
using (StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8))
requestBody = reader.ReadToEnd();
requestBody = requestBody.Replace("<base64></base64>", "");
try
{
if (requestBody.StartsWith("<?xml"))
xmlRprcRequest = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
}
catch (XmlException)
{
}
if (xmlRprcRequest != null)
{
string methodName = xmlRprcRequest.MethodName;
byte[] buf;
if (methodName != null)
{
xmlRprcRequest.Params.Add(request.RemoteIPEndPoint);
XmlRpcResponse xmlRpcResponse;
XmlRpcMethod method;
if (_server.TryGetXMLHandler(methodName, out method))
{
xmlRprcRequest.Params.Add(request.Url); // Param[2]
xmlRprcRequest.Params.Add(request.Headers.Get("X-Forwarded-For")); // Param[3]
try
{
xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
}
catch (Exception e)
{
MainConsole.Instance.ErrorFormat("[BASE HTTP SERVER]: Requested method [{0}] from {1} threw exception: {2} {3}",
methodName, request.RemoteIPEndPoint.Address, e, e.StackTrace);
// if the registered XmlRpc method threw an exception, we pass a fault-code along
xmlRpcResponse = new XmlRpcResponse();
// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(-32603, string.Format("Requested method [{0}] from {1} threw exception: {2} {3}",
methodName, request.RemoteIPEndPoint.Address, e, e.StackTrace));
}
// if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
response.KeepAlive = _server.GetXMLHandlerIsKeepAlive(methodName);
}
else
{
xmlRpcResponse = new XmlRpcResponse();
// Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(
XmlRpcErrorCodes.SERVER_ERROR_METHOD,
String.Format("Requested method [{0}] not found", methodName));
}
buf = Encoding.UTF8.GetBytes(XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse));
response.ContentType = "text/xml";
}
else
{
response.ContentType = "text/plain";
response.StatusCode = (int)HttpStatusCode.NotFound;
response.StatusDescription = "Not Found";
buf = Encoding.UTF8.GetBytes("Not found");
response.ContentEncoding = Encoding.UTF8;
}
try
{
response.OutputStream.Write(buf, 0, buf.Length);
response.Send();
}
catch (SocketException e)
{
// This has to be here to prevent a Linux/Mono crash
MainConsole.Instance.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
}
catch (IOException e)
{
MainConsole.Instance.Debug("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e);
}
return true;
}
return false;
//.........这里部分代码省略.........
示例12: GenericNotify
public XmlRpcResponse GenericNotify(XmlRpcRequest request, IPEndPoint ep)
{
XmlRpcResponse r = new XmlRpcResponse();
try
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable communicationData = (Hashtable)request.Params[1];
#region // Debug
#if DEBUG
m_log.Debug("[OMBASE]: genericNotify(...)");
foreach (DictionaryEntry requestDatum in requestData)
{
m_log.Debug("[OMBASE]: " + requestDatum.Key.ToString() + " " + (string)requestDatum.Value);
}
foreach (DictionaryEntry communicationDatum in communicationData)
{
m_log.Debug("[OMBASE]: " + communicationDatum.Key.ToString() + " " + (string)communicationDatum.Value);
}
#endif
#endregion
String method = (string)requestData["method"];
requestData.Remove("method");
if (CommunicationHelpers.ValidateRequest(communicationData, requestData, gatewayURL))
{
switch (method)
{
case "notifyUser": r.Value = userInteract(requestData);
break;
case "writeLog": r.Value = WriteLog(requestData);
break;
case "notifyIsAlive": r.Value = IsAlive(requestData);
break;
default: m_log.ErrorFormat("[{0}]: Method {1} is not supported.", Name, method);
break;
}
}
else
{
throw new Exception("Hash values do not match");
}
}
catch (Exception e)
{
m_log.ErrorFormat("[{0}]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace);
r.SetFault(1, "Could not parse the requested method");
}
return r;
}
示例13: VerifyKeyMethod
public XmlRpcResponse VerifyKeyMethod(XmlRpcRequest request, IPEndPoint remoteClient)
{
bool success = false;
XmlRpcResponse response = new XmlRpcResponse();
if (request.Params.Count != 2)
{
response.IsFault = true;
response.SetFault(-1, "Invalid parameters");
return response;
}
// Verify the key of who's calling
UUID userID = UUID.Zero;
string authKey = string.Empty;
if (UUID.TryParse((string)request.Params[0], out userID))
{
authKey = (string)request.Params[1];
m_log.InfoFormat("[AUTH HANDLER] VerifyKey called with key {0}", authKey);
success = m_LocalService.VerifyKey(userID, authKey);
}
m_log.DebugFormat("[AUTH HANDLER]: Response to VerifyKey is {0}", success);
response.Value = success;
return response;
}
示例14: HandleXmlRpcRequests
//.........这里部分代码省略.........
"[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}, length {1}. Sending blank response.",
request.RemoteIPEndPoint, requestBody.Length);
}
}
}
if (xmlRprcRequest != null)
{
string methodName = xmlRprcRequest.MethodName;
if (methodName != null)
{
xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
XmlRpcResponse xmlRpcResponse;
XmlRpcMethod method;
bool methodWasFound;
bool keepAlive = false;
lock (m_rpcHandlers)
{
methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
if (methodWasFound)
keepAlive = m_rpcHandlersKeepAlive[methodName];
}
if (methodWasFound)
{
xmlRprcRequest.Params.Add(request.Url); // Param[2]
string xff = "X-Forwarded-For";
string xfflower = xff.ToLower();
foreach (string s in request.Headers.AllKeys)
{
if (s != null && s.Equals(xfflower))
{
xff = xfflower;
break;
}
}
xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]
try
{
xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
}
catch(Exception e)
{
string errorMessage
= String.Format(
"Requested method [{0}] from {1} threw exception: {2} {3}",
methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);
m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);
// if the registered XmlRpc method threw an exception, we pass a fault-code along
xmlRpcResponse = new XmlRpcResponse();
// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(-32603, errorMessage);
}
// if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
response.KeepAlive = keepAlive;
}
else
{
xmlRpcResponse = new XmlRpcResponse();
// Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
xmlRpcResponse.SetFault(
XmlRpcErrorCodes.SERVER_ERROR_METHOD,
String.Format("Requested method [{0}] not found", methodName));
}
response.ContentType = "text/xml";
responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
}
else
{
//HandleLLSDRequests(request, response);
response.ContentType = "text/plain";
response.StatusCode = 404;
response.StatusDescription = "Not Found";
response.ProtocolVersion = "HTTP/1.0";
responseString = "Not found";
response.KeepAlive = false;
m_log.ErrorFormat(
"[BASE HTTP SERVER]: Handler not found for http request {0} {1}",
request.HttpMethod, request.Url.PathAndQuery);
}
}
byte[] buffer = Encoding.UTF8.GetBytes(responseString);
response.SendChunked = false;
response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8;
return buffer;
}
示例15: HttpPost
public void HttpPost(SimpleHttpRequest req)
{
XmlRpcRequest rpc = XmlRpcRequestDeserializer.Parse(req.Input);
XmlRpcResponse resp = new XmlRpcResponse();
Object target = _handlers[rpc.MethodNameObject];
if (target == null)
{
resp.SetFault(-1, "Object " + rpc.MethodNameObject + " not registered.");
}
else
{
try
{
resp.Value = rpc.Invoke(target);
}
catch (XmlRpcException e)
{
resp.SetFault(e.Code, e.Message);
}
catch (Exception e2)
{
resp.SetFault(-1, e2.Message);
}
}
Logger.WriteEntry(resp.ToString(), EventLogEntryType.Information);
SendHeader(req.Protocol, "text/xml", 0, " 200 OK", req.Output);
req.Output.Flush();
XmlTextWriter xml = new XmlTextWriter(req.Output);
XmlRpcResponseSerializer.Serialize(xml, resp);
xml.Flush();
req.Output.Flush();
}