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 8927241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:10:29+00:00 2026-06-15T08:10:29+00:00

Hi there I have a java code to create a SOAP message to send

  • 0

Hi there I have a java code to create a SOAP message to send a WSDL service.The code is as follows:

  SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
  SOAPConnection connection = sfc.createConnection();

  MessageFactory mf = MessageFactory.newInstance();
  SOAPMessage sm = mf.createMessage();

  SOAPHeader sh = sm.getSOAPHeader();
  SOAPBody sb = sm.getSOAPBody();


  QName bodyName = new QName("SendSMSInput");
  SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);

  QName expiryDate = new QName("EXPIRY_DATE");
  SOAPElement node = bodyElement.addChildElement(expiryDate);
  node.addTextNode("TARIH GELECEK BURAYA");

  QName message_class = new QName("MESSAGE_CLASS");
  SOAPElement node2 = bodyElement.addChildElement(message_class);
  node2.addTextNode("MESSAGE_CLASS GELECEK BURAYA");

  QName s_date = new QName("S_DATE");
  SOAPElement node3 = bodyElement.addChildElement(s_date);
  node3.addTextNode("S_DATE GELECEK BURAYA");

  QName short_number = new QName("SHORT_NUMBER");
  SOAPElement node4 = bodyElement.addChildElement(short_number);
  node4.addTextNode("SHORT NUMBER GELECEK BURAYA");

  QName src_msisdn = new QName("SRC_MSISN");
  SOAPElement node5 = bodyElement.addChildElement(src_msisdn);
  node5.addTextNode("BOŞLUK");

  QName to_rec = new QName("TO_RECEIVERS");
  SOAPElement node6 = bodyElement.addChildElement(to_rec);


  QName msisdn = new QName("msisdn");
  SOAPElement node6_1 = node6.addChildElement(msisdn);
  node6_1.addTextNode("BOŞLUK");

  QName message_body = new QName("MESSAGE_BODY");
  SOAPElement node7 = bodyElement.addChildElement(message_body);


  QName message = new QName("message");
  SOAPElement node7_1 = node7.addChildElement(message);
  node7_1.addTextNode("BOŞLUK");

which generates the following:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
    <SendSMSInput>
        <EXPIRY_DATE>TARIH GELECEK BURAYA</EXPIRY_DATE>
        <MESSAGE_CLASS>MESSAGE_CLASS GELECEK BURAYA</MESSAGE_CLASS>
        <S_DATE>S_DATE GELECEK BURAYA</S_DATE>
        <SHORT_NUMBER>SHORT NUMBER GELECEK BURAYA</SHORT_NUMBER>
        <SRC_MSISN>BOŞLUK</SRC_MSISN>
        <TO_RECEIVERS>
            <msisdn>BOŞLUK</msisdn>
        </TO_RECEIVERS>
        <MESSAGE_BODY>
            <message>BOŞLUK</message>
        </MESSAGE_BODY>
    </SendSMSInput>
</SOAP-ENV:Body>

I need to add elements under the header. When I try

QName tokenHeader = new QName("token");
  SOAPHeaderElement tokenElement = sh.addHeaderElement(tokenHeader);

it says:

HeaderElements must be namespace qualified
Exception in thread "main" com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: HeaderElements must be namespace qualified
    at com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl.addHeaderElement(HeaderImpl.java:96)
    at soapgenerator.SOAPGenerator.main(SOAPGenerator.java:34)

How can I achieve this?

  • 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-06-15T08:10:30+00:00Added an answer on June 15, 2026 at 8:10 am

    use the QName constructor that has a namespace part instead of the namespace-less constructor.

    QName(String namespaceURI, String localPart)

    QName constructor specifying the Namespace URI and local part.

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

Sidebar

Related Questions

I have java source code in a text file. There has to be entered
Have there been incompatibilities between Java releases where Java source code/Java class files targeting
I am trying to create a GUI using java swing. From there I have
I have this code to create a configuration of a java client to connect
I have this java code that renames a file (or directory). There is a
Is there a way to use my SOAP web service(spring-ws, java) as a XML
Is there any way to auto-magically create Class Diagrams from Java code? I am
We are using standard Java/SAAJ features to create SOAP messages and perform web service
I have Java-related question: I want to know is there a way to create
The Google Finance API only have Java / Javascript. Is there any ideas on

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.