Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 874015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:02:14+00:00 2026-05-15T11:02:14+00:00

I’m trying to write some code in java to learn more about coding with

  • 0

I’m trying to write some code in java to learn more about coding with WSDL and SOAP.

For example given :

'<'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 looks like this at the moment:


//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 blank. I know my endpoint is correct , as well as the checkAccount ,id and password since I’ve tested it in xmlSpy and it returns account status.

It has to be the way I’m trying to get the response. Can someone please give me a hint?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:02:15+00:00Added an answer on May 15, 2026 at 11:02 am

    This is how I would do it.

    MessageFactory factory = MessageFactory.newInstance();           
    SOAPMessage message = factory.createMessage();
    SOAPBody body = message.getSOAPBody();
    SOAPElement checkAccEl =  body
      .addChildElement("checkAccount", "to", "http://foo");
    
    SOAPElement idEl = checkAccEl
      .addChildElement("id", "to", "http://foo");
    idEl.addTextNode("test");
    
    SOAPElement passwordEl = checkAccEl
      .addChildElement("password", "to", "http://foo");
    passwordEl.addTextNode("test");
    
    // print out the SOAP Message. How easy is this?!
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    message.writeTo(out);
    System.out.println(out.toString());
    

    The first time you use the namespace ‘to=http://foo‘ it is automatically declared on the element – checkAccount in this case. When you use the same namespace again, the XML won’t need to declare it again, but will use the prefix.

    The output looks like:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
        <SOAP-ENV:Header/>
        <SOAP-ENV:Body>
            <to:checkAccount xmlns:to="http://foo">
                <to:id>test</to:id>
                <to:password>test</to:password>
             </to:checkAccount>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    Which is what you want I think

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As you are generating multiple elements, you shouldn't give them… May 15, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer The solution we finally figured out was a small registry… May 15, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer You'll need languge tables for each supported language. You may… May 15, 2026 at 5:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.