私はVisualSoft Soap Test WS ..を呼び出そうとしていますが、要求を実行しようとするたびにデフォルトのWSDLが返されますが、テスト用 。SOAPサービスを呼び出すとWSDLが返されます
私は間違いがありますか? :
コード:SOAPについて
public static void main(String args[]) throws Exception {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server.
String url = "https://demo.visualsoft.co.uk/api/soap/wsdl/3";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), new URL(url));
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
String xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://demo.visualsoft.co.uk/api/soap/service\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Header><ns1:VSAuth><ClientID>testclient</ClientID><Username>testuser</Username><Password>testpass</Password></ns1:VSAuth></SOAP-ENV:Header><SOAP-ENV:Body><ns1:HelloWorld/></SOAP-ENV:Body></SOAP-ENV:Envelope>";
MessageFactory messageFactory = MessageFactory.newInstance();
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
MimeHeaders Headers = new MimeHeaders();
SOAPMessage soapMessage = messageFactory.createMessage(Headers, is);
soapMessage.writeTo(System.out);
return soapMessage;
}
private static String convertDocumentToString(Document doc) {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tf.newTransformer();
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
String output = writer.getBuffer().toString();
return output;
} catch (TransformerException e) {
e.printStackTrace();
}
return null;
}
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.println("Response SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
詳細:https://demo.visualsoft.co.uk/api/soap#WSDL
Thaaaaanks ... 1以上さて、PHPのサンプルのようにJavaでSoapClientを処理する方法はありますか?私はXML形式全体を送信する代わりに、操作と引数だけをパラメータとして渡すことを意味しますか? – Jason4Ever