import javax.xml.soap.*; public class SOAPClient { public static void main(String[] args) { try { SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = connectionFactory.createConnection(); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPBody body = envelope.getBody(); SOAPElement operation = body.addChildElement("Operation"); SOAPElement param1 = operation.addChildElement("Param1"); param1.addTextNode("Value1"); String endpointUrl = "http://example.com/soap-service"; SOAPMessage response = connection.call(message, endpointUrl); SOAPBody responseBody = response.getSOAPBody(); String result = responseBody.getTextContent(); System.out.println("Response: " + result); connection.close(); } catch (Exception e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文