我有一个供应商的extern说送我,XML测试反序列化SOAP消息
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AVCabeza transactionID="000032" xmlns="http://webservices.patito/Core/">
<Solicitor entityID="WEST" systemType="WEB" />
</AVCabeza>
</soap:Header>
<soap:Body>
<Availability xmlns:a="http://webservices.patito/Availability/"
xmlns:hc="http://webservices.patito/Common/" summaryOnly="true"
xmlns="http://webservices.patito/og/Availability.wsdl">
<a:AvailabilityDetail availReqType="Room">
<a:Estadia>
<hc:StartDate>2009-01-05T00:00:00.0000000-05:00</hc:StartDate>
<hc:EndDate>2009-01-06T00:00:00.0000000-05:00</hc:EndDate>
</a:Estadia>
<a:HotelSearchCriteria>
<a:HotelRef chainCode="WC"/>
</a:HotelSearchCriteria>
</a:AvailabilityDetail>
</Availability>
</soap:Body>
</soap:Envelope>
我想解串器,所以我做到了
1)我使用的XSD的生成C#类
2)用类generate创建一个新的项目类库。
结构
WebServicesExterns(项目) - >服务(文件夹) --->所有类
例如
namespace WebServicesExterns.Services
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://webservices.patito/Availability.wsdl")> _
Partial Public Class Availability
'''<comentarios/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://webservices.patito/Core/"), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://webservices.patito/Core/", IsNullable:=false)> _
Partial Public Class AVCabeza
3)创建尝试一个测试类之后解串器
using WebServicesExterns.Services;
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Soap;
[Test()]
public void ShouldDeserializerSoapMessage()
{
var message = SoapToFromFile(@"C:\rq\Availability.xml");
Assert.IsNotNull(message);
}
public object SoapToFromFile(string filePath)
{
IFormatter formatter;
FileStream fileStream = null;
Object objectFromSoap = null;
try
{
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
formatter = new SoapFormatter();
objectFromSoap = formatter.Deserialize(fileStream);
}
catch (Exception exception)
{
throw exception;
}
finally
{
if (fileStream != null) fileStream.Close();
}
return objectFromSoap;
}
因此,返回该错误
解析错误,没有与XML密钥 “AVCabeza” “_p1缔合体”
调试我创办什么_p1等于 “HTTP://webservices.patito/Core/”
显然没有找到“类型”AVCabeza类
怎么了?这是供应商
新的更新
看给我
一个文件夹与结构
root
|
-- WSDL_XSD
| |-XSD
| | files with extension .xsd
| |
| --WS
| files with extension .wsdl
|-- XMLSamples
|-files with xml extension that contain soap messsages
以及我删除XML(前面的例子)头部
的<?xml version="1.0" encoding="utf-8"?>
<Availability xmlns:a="http://webservices.patito/Availability/"
xmlns:hc="http://webservices.patito/Common/" summaryOnly="true"
xmlns="http://webservices.patito/og/Availability.wsdl">
<a:AvailabilityDetail availReqType="Room">
<a:Estadia>
<hc:StartDate>2009-01-05T00:00:00.0000000-05:00</hc:StartDate>
<hc:EndDate>2009-01-06T00:00:00.0000000-05:00</hc:EndDate>
</a:Estadia>
<a:HotelSearchCriteria>
<a:HotelRef chainCode="WC"/>
</a:HotelSearchCriteria>
</a:AvailabilityDetail>
</Availability>
并将尝试获取des erializable供应对象,但现在失败这个标志
not expected "<Availability .."
在wsdl_xsd - > WS - > WS我看到的可用性存在,所以我觉得可用性换到availabilitydetail(实际要求),这是我不能删除 可用性对象标签,因为它具有儿童标签的名称空间spacefications
是什么想法呢?
也许如果我删除可用性和插入命名空间(在某种程度上)我能得到我的解串对象
对不起,我不能添加Web引用,因为存在的共同对象,我使用5 8服务和它导致冲突,所以我创建了一个代理与WSDL和生成所有类。非常感谢 – 2011-04-26 20:22:07
如果你使用WSDL创建了一个代理,那么你做了和“添加Web引用”一样的事情。这意味着你不需要做你自己的序列化。 – 2011-04-26 20:23:09