本文整理汇总了C#中CookComputing.XmlRpc.XmlRpcSerializer类的典型用法代码示例。如果您正苦于以下问题:C# XmlRpcSerializer类的具体用法?C# XmlRpcSerializer怎么用?C# XmlRpcSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlRpcSerializer类属于CookComputing.XmlRpc命名空间,在下文中一共展示了XmlRpcSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AdvogatoProblem
public void AdvogatoProblem()
{
string xml = @"<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<array>
<data>
<value>
<dateTime.iso8601>20020707T11:25:37</dateTime.iso8601>
</value>
<value>
<dateTime.iso8601>20020707T11:37:12</dateTime.iso8601>
</value>
</data>
</array>
</param>
</params>
</methodResponse>";
StringReader sr = new StringReader(xml);
XmlRpcSerializer serializer = new XmlRpcSerializer();
try
{
XmlRpcResponse response
= serializer.DeserializeResponse(sr, null);
Object o = response.retVal;
Assert.Fail("should have thrown XmlRpcInvalidXmlRpcException");
}
catch(XmlRpcInvalidXmlRpcException)
{
}
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:32,代码来源:Copy+of+deserializeresponsetest.cs
示例2: Serialize
public static XmlDocument Serialize(
string testName,
object obj,
Encoding encoding,
MappingAction action)
{
Stream stm = new MemoryStream();
XmlTextWriter xtw = new XmlTextWriter(stm, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 2;
xtw.WriteStartDocument();
XmlRpcSerializer ser = new XmlRpcSerializer();
ser.Serialize(xtw, obj, action);
xtw.Flush();
//Console.WriteLine(testName);
stm.Position = 0;
TextReader trdr = new StreamReader(stm, new UTF8Encoding(), true, 4096);
String s = trdr.ReadLine();
while (s != null)
{
//Console.WriteLine(s);
s = trdr.ReadLine();
}
stm.Position = 0;
XmlDocument xdoc = new XmlDocument();
xdoc.PreserveWhitespace = true;
xdoc.Load(stm);
return xdoc;
}
开发者ID:sgh1986915,项目名称:vfos-scraper-c-,代码行数:29,代码来源:utils.cs
示例3: AllowInvalidHTTPContentLeadingWhiteSpace
public void AllowInvalidHTTPContentLeadingWhiteSpace()
{
string xml = @"
<?xml version=""1.0"" ?>
<methodResponse>
<params>
<param>
<value><i4>12345</i4></value>
</param>
</params>
</methodResponse>";
Stream stm = new MemoryStream();
StreamWriter wrtr = new StreamWriter(stm, Encoding.ASCII);
wrtr.Write(xml);
wrtr.Flush();
stm.Position = 0;
XmlRpcSerializer serializer = new XmlRpcSerializer();
serializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
XmlRpcResponse response = serializer.DeserializeResponse(stm, typeof(int));
Object o = response.retVal;
Assert.IsTrue(o != null, "retval not null");
Assert.IsTrue(o is int, "retval is int");
Assert.AreEqual((int)o, 12345, "retval is 12345");
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:26,代码来源:Copy+of+deserializeresponsetest.cs
示例4: XmlRpcSerializer
public XmlRpcSerializer()
{
Mapper.Initialize((config) =>
{
config.CreateMap<PostStatus, string>().ConvertUsing(src => src.ToRPC());
config.CreateMap<PostOrderBy, string>().ConvertUsing(src => src.ToRPC());
config.CreateMap<Order, string>().ConvertUsing(src => src.ToRPC());
config.CreateMap<Rpc.PostFilter, PostFilterProxy>()
.ForMember(
dest => dest.PostStatus,
opt => opt.MapFrom(
source => new string[] { Mapper.Map<string>(source.PostStatus) }
)
);
});
var doc = new XmlDocument();
doc.Load("SampleData/getpost.xml");
var response = new CookComputing.XmlRpc.XmlRpcSerializer().DeserializeResponse(
doc,
typeof(Rpc.Post)
);
this._subject = response.retVal as Rpc.Post;
this._expected = this.ExpectedPost();
}
开发者ID:caseygoodhew,项目名称:wordpress-xmlrpc-client,代码行数:27,代码来源:Post.cs
示例5: SerializeObjectParams
public void SerializeObjectParams()
{
Stream stm = new MemoryStream();
XmlRpcRequest req = new XmlRpcRequest();
req.args = new Object[] { new object[] { 1, "one" } };
req.method = "Foo";
req.mi = typeof(IFoo).GetMethod("Foo");
XmlRpcSerializer ser = new XmlRpcSerializer();
ser.SerializeRequest(stm, req);
stm.Position = 0;
TextReader tr = new StreamReader(stm);
string reqstr = tr.ReadToEnd();
Assert.AreEqual(
@"<?xml version=""1.0""?>
<methodCall>
<methodName>Foo</methodName>
<params>
<param>
<value>
<i4>1</i4>
</value>
</param>
<param>
<value>
<string>one</string>
</value>
</param>
</params>
</methodCall>", reqstr);
}
开发者ID:sgh1986915,项目名称:vfos-scraper-c-,代码行数:30,代码来源:paramstest.cs
示例6: PaoloLiveraniProblem
public void PaoloLiveraniProblem()
{
try
{
XmlRpcResponse resp = new XmlRpcResponse(new DataSet());
Stream responseStream = new MemoryStream();
XmlRpcSerializer serializer = new XmlRpcSerializer();
serializer.SerializeResponse(responseStream, resp);
}
catch(XmlRpcInvalidReturnType ex)
{
string s = ex.Message;
}
}
开发者ID:ayende,项目名称:Subtext,代码行数:14,代码来源:serializeresponsetest.cs
示例7: Invoke
public Stream Invoke(Stream requestStream)
{
try
{
var serializer = new XmlRpcResponseSerializer();
var deserializer = new XmlRpcRequestDeserializer();
Type type = this.GetType();
XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
Attribute.GetCustomAttribute(this.GetType(),
typeof(XmlRpcServiceAttribute));
if (serviceAttr != null)
{
if (serviceAttr.XmlEncoding != null)
{
serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
}
serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
serializer.UseIntTag = serviceAttr.UseIntTag;
serializer.UseStringTag = serviceAttr.UseStringTag;
serializer.UseIndentation = serviceAttr.UseIndentation;
serializer.Indentation = serviceAttr.Indentation;
}
XmlRpcRequest xmlRpcReq = deserializer.DeserializeRequest(requestStream, this.GetType());
XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);
Stream responseStream = new MemoryStream();
serializer.SerializeResponse(responseStream, xmlRpcResp);
responseStream.Seek(0, SeekOrigin.Begin);
return responseStream;
}
catch (Exception ex)
{
XmlRpcFaultException fex;
if (ex is XmlRpcException)
fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
else if (ex is XmlRpcFaultException)
fex = (XmlRpcFaultException)ex;
else
fex = new XmlRpcFaultException(0, ex.Message);
XmlRpcSerializer serializer = new XmlRpcSerializer();
Stream responseStream = new MemoryStream();
serializer.SerializeFaultResponse(responseStream, fex);
responseStream.Seek(0, SeekOrigin.Begin);
return responseStream;
}
}
开发者ID:AntonWong,项目名称:cms,代码行数:48,代码来源:XmlRpcServerProtocol.cs
示例8: Serialize
public static XmlReader Serialize(
string testName,
object obj,
Encoding encoding,
MappingActions actions)
{
Stream stm = new MemoryStream();
XmlWriter xtw = XmlRpcXmlWriter.Create(stm, new XmlRpcFormatSettings());
xtw.WriteStartDocument();
XmlRpcSerializer ser = new XmlRpcSerializer();
ser.Serialize(xtw, obj, actions);
xtw.Flush();
stm.Position = 0;
XmlReader rdr = XmlRpcXmlReader.Create(stm);
return rdr;
}
开发者ID:wbrussell,项目名称:xmlrpcnet,代码行数:16,代码来源:utils.cs
示例9: XmlRpcSerializer
public XmlRpcSerializer()
{
var doc = new XmlDocument();
doc.Load("SampleData/getAuthors.xml");
var response = new CookComputing.XmlRpc.XmlRpcSerializer().DeserializeResponse(
doc,
typeof(Rpc.Author[])
);
this._subject = response.retVal as IEnumerable<Rpc.Author>;
//= new List<Author>();
this._expected = this.ExpectedAuthors();
}
开发者ID:caseygoodhew,项目名称:wordpress-xmlrpc-client,代码行数:16,代码来源:Authors.cs
示例10: SerializeToString
public static string SerializeToString(
string testName,
object obj,
MappingAction action)
{
StringWriter strwrtr = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(strwrtr);
// xtw.Formatting = formatting;
// xtw.Indentation = indentation;
xtw.WriteStartDocument();
XmlRpcSerializer ser = new XmlRpcSerializer();
ser.Serialize(xtw, obj, action);
xtw.Flush();
//Console.WriteLine(testName);
//Console.WriteLine(strwrtr.ToString());
return strwrtr.ToString();
}
开发者ID:sgh1986915,项目名称:vfos-scraper-c-,代码行数:17,代码来源:utils.cs
示例11: Invoke
public Stream Invoke(Stream requestStream)
{
try
{
var serializer = new XmlRpcResponseSerializer();
var deserializer = new XmlRpcRequestDeserializer();
var serviceAttr = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
if (serviceAttr != null)
{
if (serviceAttr.XmlEncoding != null)
serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
serializer.UseIntTag = serviceAttr.UseIntTag;
serializer.UseStringTag = serviceAttr.UseStringTag;
serializer.UseIndentation = serviceAttr.UseIndentation;
serializer.Indentation = serviceAttr.Indentation;
}
var xmlRpcReq = deserializer.DeserializeRequest(requestStream, GetType());
var xmlRpcResp = Invoke(xmlRpcReq);
var responseStream = new MemoryStream();
serializer.SerializeResponse(responseStream, xmlRpcResp);
responseStream.Seek(0, SeekOrigin.Begin);
return responseStream;
}
catch (Exception ex)
{
XmlRpcFaultException fex;
var xmlRpcException = ex as XmlRpcException;
if (xmlRpcException != null)
fex = new XmlRpcFaultException(0, xmlRpcException.Message);
else
{
fex = (ex as XmlRpcFaultException)
?? new XmlRpcFaultException(0, ex.Message);
}
var serializer = new XmlRpcSerializer();
var responseStream = new MemoryStream();
serializer.SerializeFaultResponse(responseStream, fex);
responseStream.Seek(0, SeekOrigin.Begin);
return responseStream;
}
}
开发者ID:magicmonty,项目名称:xmlrpcnet,代码行数:44,代码来源:XmlRpcServerProtocol.cs
示例12: IntegerNullType
public void IntegerNullType()
{
string xml = @"<?xml version=""1.0"" ?>
<methodResponse>
<params>
<param>
<value><int>12345</int></value>
</param>
</params>
</methodResponse>";
StringReader sr = new StringReader(xml);
XmlRpcSerializer serializer = new XmlRpcSerializer();
XmlRpcResponse response = serializer.DeserializeResponse(sr, null);
Object o = response.retVal;
Assert.IsTrue(o != null, "retval not null");
Assert.IsTrue(o is int, "retval is int");
Assert.AreEqual((int)o, 12345, "retval is 12345");
}
开发者ID:sgh1986915,项目名称:vfos-scraper-c-,代码行数:19,代码来源:deserializeresponsetest.cs
示例13: WithXmlDocPropertyPresentShouldDeserializeProperly
public void WithXmlDocPropertyPresentShouldDeserializeProperly()
{
// Arrange
var xmlSerializer = new XmlRpcSerializer();
const string reply = @"<?xml version='1.0'?>
<methodResponse><params><param>
<value><struct><member><name>XmlDoc</name><value>this is a string</value></member></struct></value>
</param></params></methodResponse>";
var expected = new P2000ReturnStructure
{
XmlDoc = "this is a string"
};
// Act
var actual = xmlSerializer.DeserializeStringResponse<P2000ReturnStructure>(reply);
// Assert
DtoAssert.AreEqual(expected, actual);
}
开发者ID:shayaneumar,项目名称:gabbar,代码行数:20,代码来源:P2000ReturnStructureTest.cs
示例14: Base64Empty
public void Base64Empty()
{
string xml = @"<?xml version=""1.0""?>
<methodCall>
<methodName>TestHex</methodName>
<params>
<param>
<value>
<base64></base64>
</value>
</param>
</params>
</methodCall>";
StringReader sr = new StringReader(xml);
XmlRpcSerializer serializer = new XmlRpcSerializer();
XmlRpcRequest request = serializer.DeserializeRequest(sr, null);
Assert.AreEqual(request.args[0].GetType(), typeof(byte[]),
"argument is byte[]");
Assert.AreEqual(request.args[0], new byte[0],
"argument is zero length byte[]");
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:22,代码来源:deserializerequesttest.cs
示例15: Base64
public void Base64()
{
string xml = @"<?xml version=""1.0""?>
<methodCall>
<methodName>TestHex</methodName>
<params>
<param>
<value>
<base64>AQIDBAUGBwg=</base64>
</value>
</param>
</params>
</methodCall>";
StringReader sr = new StringReader(xml);
XmlRpcSerializer serializer = new XmlRpcSerializer();
XmlRpcRequest request = serializer.DeserializeRequest(sr, null);
Assert.AreEqual(request.args[0].GetType(), typeof(byte[]),
"argument is byte[]");
byte[] ret = (byte[])request.args[0];
Assert.AreEqual(8, ret.Length, "argument is byte[8]");
for (int i = 0; i < ret.Length; i++)
Assert.AreEqual(i+1, ret[i], "members are 1 to 8");
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:24,代码来源:deserializerequesttest.cs
示例16: Parse
public static object Parse(
XmlDocument xdoc,
Type valueType,
MappingAction action,
XmlRpcSerializer serializer,
out Type parsedType,
out Type parsedArrayType)
{
XmlNode node = xdoc.SelectSingleNode("value").FirstChild;
XmlRpcSerializer.ParseStack parseStack
= new XmlRpcSerializer.ParseStack("request");
object obj = serializer.ParseValue(node, valueType, parseStack, action,
out parsedType, out parsedArrayType);
return obj;
}
开发者ID:molotovbliss,项目名称:csharlibformagexmlrpcapi,代码行数:15,代码来源:Copy+of+utils.cs
示例17: GetRequestStreamCallback
static void GetRequestStreamCallback(IAsyncResult asyncResult)
{
XmlRpcAsyncResult clientResult
= (XmlRpcAsyncResult)asyncResult.AsyncState;
clientResult.CompletedSynchronously = asyncResult.CompletedSynchronously;
try
{
Stream serStream = null;
Stream reqStream = null;
bool logging = (clientResult.ClientProtocol.RequestEvent != null);
if (!logging)
{
serStream = reqStream
= clientResult.Request.EndGetRequestStream(asyncResult);
}
else
serStream = new MemoryStream(2000);
try
{
XmlRpcRequest req = clientResult.XmlRpcRequest;
XmlRpcSerializer serializer = new XmlRpcSerializer();
if (clientResult.XmlEncoding != null)
serializer.XmlEncoding = clientResult.XmlEncoding;
serializer.UseEmptyParamsTag = clientResult.UseEmptyParamsTag;
serializer.UseIndentation = clientResult.UseIndentation;
serializer.Indentation = clientResult.Indentation;
serializer.UseIntTag = clientResult.UseIntTag;
serializer.UseStringTag = clientResult.UseStringTag;
serializer.SerializeRequest(serStream, req);
if (logging)
{
reqStream = clientResult.Request.EndGetRequestStream(asyncResult);
serStream.Position = 0;
Util.CopyStream(serStream, reqStream);
reqStream.Flush();
serStream.Position = 0;
clientResult.ClientProtocol.OnRequest(
new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream));
}
}
finally
{
if (reqStream != null)
reqStream.Close();
}
clientResult.Request.BeginGetResponse(
new AsyncCallback(GetResponseCallback), clientResult);
}
catch (Exception ex)
{
ProcessAsyncException(clientResult, ex);
}
}
开发者ID:adzerk,项目名称:OpenX.Net,代码行数:53,代码来源:XmlRpcClientProtocol.cs
示例18: ReadResponse
XmlRpcResponse ReadResponse(
XmlRpcRequest req,
WebResponse webResp,
Stream respStm,
Type returnType)
{
HttpWebResponse httpResp = (HttpWebResponse)webResp;
if (httpResp.StatusCode != HttpStatusCode.OK)
{
// status 400 is used for errors caused by the client
// status 500 is used for server errors (not server application
// errors which are returned as fault responses)
#if (!SILVERLIGHT)
if (httpResp.StatusCode == HttpStatusCode.BadRequest)
throw new XmlRpcException(httpResp.StatusDescription);
else
throw new XmlRpcServerException(httpResp.StatusDescription);
#else
throw new XmlRpcServerException(httpResp.StatusDescription);
#endif
}
XmlRpcSerializer serializer = new XmlRpcSerializer();
serializer.NonStandard = _nonStandard;
Type retType = returnType;
if (retType == null)
retType = req.mi.ReturnType;
XmlRpcResponse xmlRpcResp
= serializer.DeserializeResponse(respStm, retType);
return xmlRpcResp;
}
开发者ID:adzerk,项目名称:OpenX.Net,代码行数:30,代码来源:XmlRpcClientProtocol.cs
示例19: Invoke
public object Invoke(
Object clientObj,
MethodInfo mi,
params object[] parameters)
{
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
_responseHeaders = null;
_responseCookies = null;
#endif
WebRequest webReq = null;
object reto = null;
try
{
string useUrl = GetEffectiveUrl(clientObj);
webReq = GetWebRequest(new Uri(useUrl));
XmlRpcRequest req = MakeXmlRpcRequest(webReq, mi, parameters,
clientObj, _xmlRpcMethod, _id);
SetProperties(webReq);
#if (!SILVERLIGHT)
SetRequestHeaders(_headers, webReq);
#endif
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
SetClientCertificates(_clientCertificates, webReq);
#endif
Stream serStream = null;
Stream reqStream = null;
bool logging = (RequestEvent != null);
if (!logging)
serStream = reqStream = webReq.GetRequestStream();
else
serStream = new MemoryStream(2000);
try
{
XmlRpcSerializer serializer = new XmlRpcSerializer();
if (_xmlEncoding != null)
serializer.XmlEncoding = _xmlEncoding;
serializer.UseIndentation = _useIndentation;
serializer.Indentation = _indentation;
serializer.NonStandard = _nonStandard;
serializer.UseStringTag = _useStringTag;
serializer.UseIntTag = _useIntTag;
serializer.UseEmptyParamsTag = _useEmptyParamsTag;
serializer.SerializeRequest(serStream, req);
if (logging)
{
reqStream = webReq.GetRequestStream();
serStream.Position = 0;
Util.CopyStream(serStream, reqStream);
reqStream.Flush();
serStream.Position = 0;
OnRequest(new XmlRpcRequestEventArgs(req.proxyId, req.number,
serStream));
}
}
finally
{
if (reqStream != null)
reqStream.Close();
}
HttpWebResponse webResp = GetWebResponse(webReq) as HttpWebResponse;
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
_responseCookies = webResp.Cookies;
#endif
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
_responseHeaders = webResp.Headers;
#endif
Stream respStm = null;
Stream deserStream;
logging = (ResponseEvent != null);
try
{
respStm = webResp.GetResponseStream();
if (!logging)
{
deserStream = respStm;
}
else
{
deserStream = new MemoryStream(2000);
Util.CopyStream(respStm, deserStream);
deserStream.Flush();
deserStream.Position = 0;
}
#if (!COMPACT_FRAMEWORK && !SILVERLIGHT)
deserStream = MaybeDecompressStream((HttpWebResponse)webResp,
deserStream);
#endif
try
{
XmlRpcResponse resp = ReadResponse(req, webResp, deserStream, null);
reto = resp.retVal;
}
finally
{
if (logging)
{
deserStream.Position = 0;
OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number,
deserStream));
}
//.........这里部分代码省略.........
开发者ID:adzerk,项目名称:OpenX.Net,代码行数:101,代码来源:XmlRpcClientProtocol.cs
示例20: DeserializeMessage
IMessage DeserializeMessage(
IMethodCallMessage mcm,
ITransportHeaders headers,
Stream stream)
{
XmlRpcSerializer serializer = new XmlRpcSerializer();
object tp = mcm.MethodBase;
System.Reflection.MethodInfo mi = (System.Reflection.MethodInfo)tp;
System.Type t = mi.ReturnType;
XmlRpcResponse xmlRpcResp = serializer.DeserializeResponse(stream, t);
IMessage imsg = new ReturnMessage(xmlRpcResp.retVal, null, 0, null, mcm);
return imsg;
}
开发者ID:RyanGrange,项目名称:Ketarin,代码行数:13,代码来源:XmlRpcClientFormatterSink.cs
注:本文中的CookComputing.XmlRpc.XmlRpcSerializer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论