Frequently Asked Questions: Common errors and solutions for Javax XML SOAP API

Frequently Asked Questions: Common errors and solutions for Javax XML SOAP API Question 1: javax.xml.ws.WebServiceException: Unable to create a service Solution: Make sure the correct WSDL address is specified correctly and the service access can be accessible.Please check the URL and try to re -create the service. String wsdlUrl = "http://example.com/myService?wsdl"; URL url = new URL(wsdlUrl); QName serviceName = new QName("http://example.com/myService", "MyService"); Service service = Service.create(url, serviceName); Question 2: javax.xml.soap.sopException: The removal mark is invalid Solution: When using SOAP envelope, make sure to set the `Mustunderstand` correctly to the string" 1 "or" TRUE ". SOAPMESSAGE SOAPMESSAGE = // Create SOAP messages and set content SOAPHeader soapHeader = soapMessage.getSOAPHeader(); SOAPHeaderElement headerElement = soapHeader.addHeaderElement(new QName("http://example.com/headers", "HeaderElement")); headerElement.setMustUnderstand(true); Question 3: javax.xml.Soap.sopException: Failure to analyze the message to be sent Solution: Please make sure that the XML content of the SOAP message is valid and conforms to the SOAP message structure defined by WSDL. SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); // Set the content of soap message Question 4: javax.xml.soap.sopException: Can't extract information from the message Solution: Make sure you use the correct node name and naming space when extracting information from SOAP messages. SOAPMESSAGE SOAPMESSAGE = // SOAP message received SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); Iterator<SOAPElement> it = soapBody.getChildElements(new QName("http://example.com/namespace", "ElementName")); Question 5: javax.xml.soap.sopException: Unable to create a SOAP connection Solution: Make sure that the URL connected to the SOAP server is correct, and an effective network connection has been established. String endpointUrl = "http://example.com/soap"; SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); SOAPMESSAGE SOAPREQUEST = // Create SOAP request message SOAPMessage soapResponse = soapConnection.call(soapRequest, endpointUrl); The above are some common errors and solutions to the common errors and solutions of Javax XML SOAP API.I hope these solutions can help you solve trouble when you encounter similar problems.