大家好我正在使用soap webservices,我已经为soap请求创建了java客户端,但我得到了inavalid内容类型异常。
java客户端如下
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
public class SOAPWebClient {
public static void main(String args[]) throws Exception {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
.newInstance();
SOAPConnection soapConnection = soapConnectionFactory
.createConnection();
// Send SOAP Message to SOAP Server
String url = "http://127.0.0.1/sysworkflow/en/classic/services/wsdl2";
SOAPMessage soapResponse = soapConnection
.call(createSOAPRequest(), url);
// print SOAP Response
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
soapConnection.close();
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://www.processmaker.com";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("proc", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("login", "proc");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid",
"proc");
soapBodyElem1.addTextNode("admin");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("password",
"proc");
soapBodyElem2.addTextNode("admin");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "login");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
}
我尝试过使用SOAPUI,我得到了正确的响应
我的客户代码是:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:proc="http://www.processmaker.com">
<soap:Header/>
<soap:Body>
<proc:login>
<proc:userid>admin</proc:userid>
<proc:password>admin</proc:password>
</proc:login>
</soap:Body>
</soap:Envelope>
服务器响应是:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.processmaker.com">
<env:Body>
<ns1:loginResponse>
<ns1:status_code>0</ns1:status_code>
<ns1:message>5986328125354e253db2dc6036456081</ns1:message>
<ns1:version>2.0</ns1:version>
<ns1:timestamp>2014-04-21 05:18:11</ns1:timestamp>
</ns1:loginResponse>
</env:Body>
</env:Envelope>
请帮帮我
谢谢