原始的请求如下
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://www.2345.com/switch">
<soapenv:Header/>
<soapenv:Body>
<ns2:subscriptionRequest>
<ns2:id>1</ns2:id>
<ns2:name>2</ns2:name>
<ns2:email>3</ns2:email>
</ns2:subscriptionRequest>
</soapenv:Body>
</soapenv:Envelope>
实际要求的格式如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<subscriptionRequest xmlns="http://www.2345.com/switch">
<id>1</id>
<name>2</name>
<email>3</email>
</subscriptionRequest>
</soapenv:Body>
</soapenv:Envelope>
解决办法如下:
在你的subscriptionRequest这个Model包目录下新建package-info.java
@XmlSchema( namespace = "http://www.2345.com/switch", elementFormDefault = XmlNsForm.QUALIFIED, xmlns = { @XmlNs(prefix = "", namespaceURI = "http://www.2345.com/switch") } ) package com.test.model; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlSchema;
当然你也可以prefix替换成你自己定义的命名空间的别名