0

我正在尝试调用一个需要数组作为参数的 web 服务,但我不知道该怎么做,我没有 wsdl,我想使用 javax 来做到这一点。

    String operation = "TheOperationName";    
    String urn = "TheWebService";
    String destination = "http://my-server/something.php";

    // First create the connection
    SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnFactory.createConnection();


      // Next, create the actual message
      MessageFactory messageFactory = MessageFactory.newInstance();
      SOAPMessage message = messageFactory.createMessage();

      SOAPPart soapPart = message.getSOAPPart();
      SOAPEnvelope envelope = soapPart.getEnvelope();
      envelope.addNamespaceDeclaration("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/");
        // Create and populate the body
        SOAPBody body = envelope.getBody();

     // Create the main element and namespace
        SOAPElement operationItem = body.addChildElement(
                envelope.createQName(operation, "ns1"));

//这里我迷路了,我应该创建一个数组

参数 0 SOAP-ENC:arrayType="SOAP-ENC:Struct[1]" xsi:type="SOAP-ENC:Array"

其中包含我的项目数组

        SOAPElement itemElement = myarray.addChildElement("item");

        // Add parameters
        itemElement.addChildElement("ID_Bug").addTextNode("ID");
        itemElement.addChildElement("ID_Release").addTextNode("RELEASE");

        // Save the message
        message.saveChanges();

        // Send the message and get the reply
        SOAPMessage reply = connection.call(message, destination);
        reply.toString();

        // Close the connection           
        connection.close();

关于如何实现这一目标的任何建议?

4

0 回答 0