我有第三方服务器的轮.。 Ran svcutil and end up wih a set of a set of a group
XmlNode AMethod(object Request);
方法。 另有100页,说明每种方法的反应/要求物体。
我的思想是总结网络方法,利用XmlSerializer来回重打的物体。 返回的Xml looks照(一除肥皂头盔):
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ResponseExt"
xmlns="http://www.thirdparty.com/lr/">
<Code>0</Code>
<Message>SUCCESS</Message>
<SessionId>session_token</SessionId>
</Response>
简单。 创立一个班级(从文件/记录中):
[XmlRoot("Response")]
//EDIT added XmlType
[XmlType("ResponseExt", Namespace = "http://www.thirdparty.com/lr/")]
public class MyClass {
public string Code {get; set;}
public string Message {get; set;}
public string SessionId {get; set;}
}
处理时间:
//XmlNode node = xml from above
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
XmlNodeReader reader = new XmlNodeReader(node);
Myclass myclass = serializer.Deserialize(reader) as MyClass
Last line is where it blows up with inner exception message: The specified type was not recognized: name= ResponseExt , namespace= http://www.thirdparty.com/lr/ , at <Response xmlns=
>.
I can t figure out how to make Serializer happy and what exactly these two mean
xsi:type="ResponseExt" xmlns="http://www.thirdparty.com/lr/
一如既往地欢迎任何建议和协调人。
EDIT:接受的答复如下。
I was still getting exception, until i found this, hopefully it ll save someone some time. I started to work backwards. Captured xml on the wire. Deserialized to my created classes with correct attributes: worked like a charm. Tried again from webservice - exception. For some reason XmlSerializer doesn t recognize ResponseExt.
XmlSerializer serializer = new XmlSerializer(typeof(Response));
XmlNode node = (XmlNode)results[0];
XmlDocument doc = new XmlDocument();
doc.LoadXml(node.OuterXml); //reload node
XmlNodeReader reader = new XmlNodeReader(doc.FirstChild); //there is only one node
Response rsp = serializer.Deserialize(reader) as Response; //works
EDIT:基本问题卷宗不完整。 在为此花费了2天并找到了这段工作之后,第三方供应商提供了complete。 WSDL, 各种类型的电离层,无差错。