public executeRequest ( string _request ) : string | ||
_request | string | |
return | string |
public string executeRequest(string _request)
{
string _response = "";
XmlRpcValue parms = new XmlRpcValue(), resultValue = new XmlRpcValue();
string methodName = parseRequest(parms, _request);
XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.WARNING, "XmlRpcServerConnection::executeRequest: server calling method '{0}'", methodName);
try
{
if (!executeMethod(methodName, parms, resultValue) &&
!executeMulticall(methodName, parms, resultValue))
_response = generateFaultResponse(methodName + ": unknown method name");
else
_response = generateResponse(resultValue.toXml());
}
catch (XmlRpcException fault)
{
XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.WARNING, "XmlRpcServerConnection::executeRequest: fault {0}.", fault.Message);
_response = generateFaultResponse(fault.Message, fault.getCode());
}
return _response;
}
private bool writeResponse(string request) { string response = server.executeRequest(request); if (response.Length == 0) { XmlRpcUtil.error("XmlRpcServerConnection::writeResponse: empty response."); return(false); } try { MemoryStream memstream = new MemoryStream(); using (StreamWriter writer = new StreamWriter(memstream)) { writer.Write(response); _bytesWritten = response.Length; } try { var buffer = memstream.GetBuffer(); stream.Write(buffer, 0, buffer.Length); } catch (Exception ex) { XmlRpcUtil.error(string.Format("Exception while writing response: {0}", ex.Message)); } } catch (Exception ex) { XmlRpcUtil.error("XmlRpcServerConnection::writeResponse: write error ({0}).", ex.Message); return(false); } /*catch (Exception ex) * { * XmlRpcUtil.error("XmlRpcServerConnection::writeResponse: write error ({0}).", ex.Message); * return false; * }*/ XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcServerConnection::writeResponse: wrote {0} of {0} bytes.", _bytesWritten, response.Length); // Prepare to read the next request if (_bytesWritten == response.Length) { response = ""; _connectionState = ServerConnectionState.READ_HEADER; } return(_keepAlive); // Continue monitoring this source if true }