【问题标题】:How are SOAP web service namespaces customized如何自定义 SOAP Web 服务命名空间
【发布时间】: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 可以正确地反序列化传入的请求。

【问题讨论】:

标签: asp.net-core web-services soap wcf-data-services soapcore


【解决方案1】:

您可以尝试在命名空间 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 作为前缀。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多