I am trying to write some code in java to learn more about coding using WSDL and SOAP.
For instance:
'<'to:checkAccount xmlns:to="http://foo"> '<'to:id> test '<'/to:id> '<'to:password> test '<'/to:password> '<'to:checkAccount >"
'<'element name="checkAccountResponse"> '<'complexType> '<'sequence> '<'element name="checkAccountReturn" type="impl:account"/> '<'/sequence> '<'/complexType> '<'/element>
'<'complexType name="account"> '<'sequence> '<'element name="active" type="xsd:boolean"/> '<'element name="name" type="xsd:string"/> '<'/sequence> '<'/complexType>
my code is as follows:
//create the message String endpoint = "http://foo/someAPI"; MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPPart soapPart = message.getSOAPPart(); SOAPEnvelope envelope = soapPart.getEnvelope(); SOAPHeader header = message.getSOAPHeader(); //adding to the body SOAPBody body = message.getSOAPBody(); SOAPFactory soapFactory = SOAPFactory.newInstance(); Name bodyName = soapFactory.createName("checkAccount","to","http://foo"); SOAPElement bodyElement = body.addBodyElement(bodyName); //add the ID child elements soapFactory = SOAPFactory.newInstance(); Name childName = soapFactory.createName("id","to","http://foo"); SOAPElement symbol = bodyElement.addChildElement(childName); symbol.addTextNode("test"); //add password child element soapFactory = SOAPFactory.newInstance(); childName = soapFactory.createName("password","to","http://foo"); symbol = bodyElement.addChildElement(childName); symbol.addTextNode("test"); //call and get the response SOAPMessage response = sc.call(message,endpoint); //print the response SOAPBody responseBody = response.getSOAPBody(); java.util.Iterator iterator = responseBody.getChildElements(bodyName); . . . //the response is blank so trying to iterate through it gives the exception
I run this and I get nothing in return, just empty. I know that my endpoint is correct, as well as checkAccount, id and password, since I tested it in xmlSpy and it returns the status of the account.
This should be the way I'm trying to get an answer. Can someone please give me a hint?
source share