我正在使用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; }
}
這會生成一個 Web 服務請求:
<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 可以正確地反序列化傳入的請求。
uj5u.com熱心網友回復:
您可以嘗試在命名空間 iDataContract 中定義 WebSvcResponseClass,也可以使用 [DataMember] 而不是 [MessageBodyMember] 裝飾屬性。此外,您可以將服務介面定義為
public interface INewWebsServices
{
[System.ServiceModel.OperationContractAttribute(Action = "http://domain/namespace", ]
Task<iDataContract.WebSvcResponseClass> WebServiceReqactionMethod_A(iDataContract.WebserviceRequestclass composite);
}
如果您使用soapUI 嘗試使用命名空間,則會在Web 服務請求中生成idat作為前綴。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/396068.html
標籤:asp.net核心 网页服务 肥皂 wcf-数据服务 肥皂核
