Web服务将其WSDL定义发送为其响应



我正在向Web服务发送肥皂请求,但它将其WSDL定义发送回其响应。

什么会导致这?

响应:

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.sample.com/test_request" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.sample.com/test_request" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <wsdl:types>
        <xsd:schema e

代码:

import javax.xml.soap.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class Test {
    /**
     * Starting point for the SAAJ - SOAP Client Testing
     */
    public static void main(String args[]) {
        try {
            // Create SOAP Connection
            SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();
            // Send SOAP Message to SOAP Server
            String url = "https://xxxxxxxxxxx.xxxxxxxxx.com/xxxxxxxx.do?WSDL&xxxxxxxxx=qualified";
            SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), 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 {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        String serverURI = "http://www.xxxxxxxx.com/xxxxxx";
        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("a", "http://www.xxxxxxw.com/xxxxxxxx");
        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement("test", "a");
        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("testid", "a");
        soapBodyElem1.addTextNode("xxxxxxxxx");
        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", "http://www.xxxxxx-xxxxx.com/xxxxxxx/xxxx");

        String username = "123";
        String password = "123";
        String authorization = new sun.misc.BASE64Encoder().encode((username + ":" + password).getBytes());
        System.out.println(authorization);
        headers.addHeader("Authorization", "Basic " + authorization);
        headers.addHeader("Proxy-Connection","Keep-Alive");

        soapMessage.saveChanges();
        /* Print the request message */
        System.out.println("Request: ");
        soapMessage.writeTo(System.out);
        System.out.println();
        return soapMessage;
    }
    /**
     * Method used to print the SOAP Response
     */
    private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        Source sourceContent = soapResponse.getSOAPPart().getContent();
         System.out.print("nResponse SOAP Message = ");
        StreamResult result = new StreamResult(System.out);
        transformer.transform(sourceContent, result);
    }
}

是什么原因引起了这个问题?我从SOAP UI

得到适当的回应

您在URL中指定以获取WSDL(参数?WSDL)。您需要为要调用的服务操作指定适当的URL。

最新更新