【发布时间】:2022-01-17 08:05:46
【问题描述】:
我正在使用soapcore 在asp.net core 中编写一个soap web 服务来替换现有的web 服务。调用者的请求 xml 不能更改,因为我们打算尽量减少那一侧的更改。 当前请求 xml 看起来像
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://vendornamespace.com/"
xmlns:idat="http://schemas.datacontract.org/2004/07/iDataContract">
<soapenv:Header/>
<soapenv:Body>
<ser:ActionRequest>
<ser:composite>
<idat:param1>H04</idat:param1>
<idat:param2>100</idat:param2>
</ser:composite>
</ser:PlaceOrder>
</soapenv:Body>
</soapenv:Envelope>
我的网络服务界面看起来像
public interface INewWebsServices
{
[OperationContract(Action = "ActionRequest")]
Task<WebSvcResponseClass> ActionRequest([MessageParameter(Name = "composite")] WebServiceReqactionMethod_A);
}
我的请求类看起来像
[DataContract (Namespace = "http://schemas.datacontract.org/2004/07/iDataContract", Name ="idat")]
[MessageContract()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.datacontract.org/2004/07/iDataContract")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.datacontract.org/2004/07/iDataContract", IsNullable = false)]
public class WebServiceReq
{
[MessageBodyMember]
public string param1 { get; set; }
[MessageBodyMember]
public string param2 { get; set; }
}
这会生成一个网络服务请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://vendornamespace.com/">
<soapenv:Header/>
<soapenv:Body>
<ser:PlaceOrder>
<ser:composite>
<ser:param1>?</ser:param1>
<ser:param2>?</ser:param2>
</ser:composite>
</ser:PlaceOrder>
</soapenv:Body>
</soapenv:Envelope>
很明显,标头中缺少 idat 命名空间,并且未在 Web 请求参数中使用。
如何修改我的 WebServiceReq 类以包含缺少的命名空间,以便 SoapCore 可以正确地反序列化传入的请求。
【问题讨论】:
-
您可以阅读this article 找到解决方案。
标签: asp.net-core web-services soap wcf-data-services soapcore