本文整理汇总了C#中CookComputing.XmlRpc.XmlRpcSerializer类的典型用法代码示例。如果您正苦于以下问题:C# XmlRpcSerializer类的具体用法?C# XmlRpcSerializer怎么用?C# XmlRpcSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlRpcSerializer类属于CookComputing.XmlRpc命名空间,在下文中一共展示了XmlRpcSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
}
}
示例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;
}
示例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");
}
示例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();
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
}
示例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");
}
示例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);
}
示例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[]");
}
示例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");
}