Soap version mismatch in java

2020-08-03 04:38发布

问题:

Soap-request generated Java application [Failed]

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:dir="http://xxxxxxxxxx">
  <soapenv:Body>
    <xxxxxxxxxxx>       
  </soapenv:Body>
</soapenv:Envelope>

Soap-request generated by SoapUI [Successful]

 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
   xmlns:dir="http://xxxxxxxxxx">
 <soap:Header/>
   <soap:Body>
     <dir:ping/>
   </soap:Body>
 </soap:Envelope>

How to change namespace uri "http://schemas.xmlsoap.org/soap/envelope/" to "http://www.w3.org/2003/05/soap-envelope". I haven't created any client, i have just created java class and running i'm able to send request and getting faultcode response because of the above uri links. I found it is version mismatch but i dont know how to change.

回答1:

I feel that you must be using the default SOAP implementation(which is SOAP 1.2) as provided into the Statckoverflow question. Your web service may be expecting SOAP 1.1.

If you could change it SOAPMessageFactory1_1Impl implementation it should solve your problem. Your namespace will changed to xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

Change callSoapWebService method first line to following and it should resolve the issue.

SOAPMessage soapMessage = SOAPMessageFactory1_1Impl.newInstance().createMessage();

Hope it helps.



回答2:

MessageFactory factory = MessageFactory.newInstance(); ------ it will give 1.1 version default

change to following to get the 1.2 version of soap namespace

MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

you can find it in SAAJ tutorials



标签: java soap