java - 调用 SOAP 服务返回 WSDL

标签 java soap soap-client saaj

我正在尝试调用 VisualSoft Soap Test WS .. 但每次我尝试执行请求时 .. 它都会返回默认 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);
}

有关 SOAP 的更多详细信息:https://demo.visualsoft.co.uk/api/soap#WSDL

最佳答案

请求应发送至 https://demo.visualsoft.co.uk/api/soap/service/3,如 WSDL 的 service 中所示.

关于java - 调用 SOAP 服务返回 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42925615/

相关文章:

php - 使用 SoapClient 调用同名的多个方法

c# - 从 ASP.NET 4.5 应用程序使用需要 WS-Security 的 Web 服务

java - 防止IE缓存

Java REST/SOAP服务技术栈

java - 无法解析与前缀 'diffgr' 关联的命名空间。在 Castor 中

java - 使用 AXIS2 将用户/密码添加到 SOAPHeader 以进行 WebService 客户端调用

有响应时 PHP SoapClient 故障

java - 那么,如何链接Java和HTML呢?

java - 持久性模型与 View 模型

java - Jongo vs (DBObject)JSON.parse