Package org. example. myservice; import java. io. IOException; import java.net. malformedURLException; import java.net. URL; import javax. xml. namespace. QName; import javax. xml. soap. messageFactory; import javax. xml. soap. SOAPBody; import javax. xml. soap. SOAPElement; import javax. xml. soap. SOAPEnvelope; import javax. xml. soap. SOAPException; import javax. xml. soap. SOAPMessage; import javax. xml. soap. SOAPPart; import javax. xm L. ws. dispatch; import javax. xml. ws. service; import org. junit. test; import org. w3c. dom. node; import org. w3c. dom. nodeList; public class JunitTest {private String ns = "http://www.example.org/MyService/"; private String wsdlUrl = "http: // 10.10.9.208: 8088/MS? Wsdl "; @ Testpublic void testMessage () {// 1, create a message factory try {MessageFactory factory = MessageFactory. newInstance (); // 2. Create SOAPMessageSOAPMessage messge = factory based on the message factory. createMessage (); // 3, create SOAPPartSOAPPart part = messge. getSOAPPart (); // 4, get the envelope SOAPEnvelope envelop = part. getEnvelope (); // 5. Obtain the SOAPBody body = envelop in the message topic. getBody (); // 6, create information QName qname = new QName (wsdlUrl, "add", "ns"); SOAPElement ele = body. addBodyElement (qn Ame); ele. addChildElement ("number1 "). setValue ("1"); ele. addChildElement ("number2 "). setValue ("2"); messge. writeTo (System. out);} catch (SOAPException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}/// test to send the message to the server @ Testpublic void testSendMessge () {// 1, and create the Service try {URL url = new URL (wsdlUrl ); QName qname = new QName (ns, "MySe RviceImplService "); Service service Service = Service. create (url, qname); // 2, create DispicathcDispatch <SOAPMessage> dispatch = service. createDispatch (new QName (ns, "MyServiceImplPort"), SOAPMessage. class, Service. mode. MESSAGE); // 3, create the message SOAPMessage MESSAGE = MessageFactory. newInstance (). createMessage (); SOAPBody body = message. getSOAPPart (). getEnvelope (). getBody (); SOAPElement ele = body. addChildElement (new QName (ns, "add", "nn" ); Ele. addChildElement ("number1 "). setValue ("12"); ele. addChildElement ("number2 "). setValue ("13"); SOAPMessage response = dispatch. invoke (message); // response. writeTo (System. out); NodeList nodeList = response. getSOAPBody (). getElementsByTagName ("result"); Node node = nodeList. item (0); System. out. println (node. getTextContent (); // you can use the expected value in this way .} Catch (MalformedURLException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (SOAPException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace ();}}}