簡體   English   中英

JAX-WS SOAP請求主體參數的JAXB綁定

[英]JAXB binding for JAX-WS SOAP request body parameters

我正在用Java為Windows Phone 8(WP8)Enterprise MDM編寫SOAP Web服務。 客戶端是WP8,它的SOAP請求將如下所示,我無權對此請求進行任何更改。

<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/windows/management/2012/01/enrollment/IDiscoveryService/Discover</a:Action>
      <a:MessageID>urn:uuid: 748132ec-a575-4329-b01b-6171a9cf8478</a:MessageID>
      <a:ReplyTo>
         <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
      </a:ReplyTo>
      <a:To s:mustUnderstand="1">https://ENROLLTEST.CONTOSO.COM/EnrollmentServer/Discovery.svc</a:To>
   </s:Header>
   <s:Body>
      <Discover xmlns="http://schemas.microsoft.com/windows/management/2012/01/enrollment/">
         <request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <EmailAddress>user@contoso.com</EmailAddress>
            <RequestVersion>1.0</RequestVersion>
         </request>
      </Discover>
   </s:Body>
</s:Envelope>

以下是我的服務班,

@WebService(targetNamespace = "http://schemas.microsoft.com/windows/management/2012/01/enrollment/")
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
@Addressing(enabled=true, required=true)
public interface DiscoveryService {

    @WebMethod(operationName = "Discover")
    SOAPMessage handleDiscoveryRequest(@WebParam(name = "request",targetNamespace = "http://www.w3.org/2001/XMLSchema-instance")
                                       DiscoveryRequest request) throws Exception;
}

和請求主體xml映射類,

@XmlRootElement(name = "request", namespace = "http://www.w3.org/2001/XMLSchema-instance")
@XmlAccessorType(XmlAccessType.FIELD)
public class DiscoveryRequest {

    @XmlElement(name = "EmailAddress", namespace = "http://www.w3.org/2001/XMLSchema-instance")
    private String emailId;

    @XmlElement(name = "RequestVersion", namespace = "http://www.w3.org/2001/XMLSchema-instance")
    private String version;

    // Getters and Setters
}

但是,從SOAP-UI中,我獲得了帶有生成的WSDL的以下示例請求

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:enr="http://schemas.microsoft.com/windows/management/2012/01/enrollment/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Header/>
   <soap:Body>
      <enr:Discover>
         <!--Optional:-->
         <xsi:request>
            <!--Optional:-->
            <xsi:EmailAddress>?</xsi:EmailAddress>
            <!--Optional:-->
            <xsi:RequestVersion>?</xsi:RequestVersion>
         </xsi:request>
      </enr:Discover>
   </soap:Body>
</soap:Envelope>

而且,當我發送預期的請求(第一個代碼捕捉)時,我在SOAP-UI中收到以下錯誤響應

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
   <soap:Header>
      <Action xmlns="http://www.w3.org/2005/08/addressing">http://schemas.microsoft.com/windows/management/2012/01/enrollment/DiscoveryService/Discover/Fault/UnmarshalException</Action>
      <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:d81dbc0f-cbd4-41dc-aa62-aed06f3c2dc6</MessageID>
      <To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
      <RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid: 748132ec-a575-4329-b01b-6171a9cf8478</RelatesTo>
   </soap:Header>
   <soap:Body>
      <soap:Fault>
         <soap:Code>
            <soap:Value>soap:Sender</soap:Value>
         </soap:Code>
         <soap:Reason>
            <soap:Text xml:lang="en">Unmarshalling Error: unexpected element (uri:"http://schemas.microsoft.com/windows/management/2012/01/enrollment/", local:"request"). Expected elements are &lt;{http://www.w3.org/2001/XMLSchema-instance}request></soap:Text>
         </soap:Reason>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

關於如何解決此JAXB綁定名稱空間問題的任何幫助?

Unmarshalling Error: unexpected element (uri:"http://schemas.microsoft.com/windows/management/2012/01/enrollment/", local:"request"). Expected elements are &lt;{http://www.w3.org/2001/XMLSchema-instance}request

示例請求和映射不匹配。

在第一個請求中,元素“ request”位於“ ... / enrollment”命名空間中。 盡管為它定義了xmlns:i,但未設置前綴,因此它繼承了默認名稱空間,該名稱空間在父級設置:

<Discover xmlns="http://schemas.microsoft.com/windows/management/2012/01/enrollment/">
     <request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

因此錯誤消息是完全正確的。

為了使該示例請求符合您的意圖(並符合WSDL),您應該

     <i:request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

注意前綴“ i:”。

如果該請求是規范的(例如,它是一個正確的請求,作為示例提供),那么顯然應該更新映射,例如,刪除XMLSchema-instance作為targetNamespace。

其余的看起來很隨意。 通常,在處理SOAP時,我建議也提供WSDL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM