我正在为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 <{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 <{http://www.w3.org/2001/XMLSchema-instance}request
答案 0 :(得分:1)
示例请求和映射不匹配。
在第一个请求中,元素'request'位于'... / enrollment'命名空间中。尽管xmlns:i是为它定义的,但未设置前缀,因此它继承了默认命名空间,该命名空间设置为parent:
<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。