繁体   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