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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:32:58+00:00 2026-05-22T02:32:58+00:00

i’m working with SOA using WebServices. So i need to send a XML request

  • 0

i’m working with SOA using WebServices.
So i need to send a XML request to receive another XML with the response.

I create this class:

package com.ws.test;

import java.net.*;
import java.io.*;

public class SendXML {

    public static void main(String[] args) {

        try {
            String strSOAP = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

            strSOAP += "<SOAP-ENV:Envelope ";

            strSOAP += " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/";

            strSOAP += " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/";

            strSOAP += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance";

            strSOAP += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema";

            strSOAP += " xmlns:ns=\"urn:bacnet_ws\">";

            strSOAP += " <SOAP-ENV:Body SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">";

            strSOAP += " <ns:getValue>";

            strSOAP += " <ns:options></ns:options>";

            strSOAP += " <ns:path>/.sysinfo/.vendor-name</ns:path>";

            strSOAP += " </ns:getValue>";

            strSOAP += " </SOAP-ENV:Body>";

            strSOAP += "</SOAP-ENV:Envelope>";


            //Create socket
            String hostname = "192.168.1.2";
            int port = 8080;
            InetAddress addr = InetAddress.getByName(hostname);
            Socket sock = new Socket(addr, port);

            //Send header
            String path = "/rcx-ws/rcx";
            BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
            // You can use "UTF8" for compatibility with the Microsoft virtual machine.
            wr.write("POST " + path + " HTTP/1.0\r\n");
            wr.write("Host: 192.168.1.2\r\n");
            wr.write("Content-Length: " + strSOAP.length() + "\r\n");
            wr.write("Content-Type: text/xml; charset=\"utf-8\"\r\n");
            wr.write("\r\n");

            //Send data
            wr.write(strSOAP);
            wr.flush();

            // Response
            BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {

                System.out.println(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

But this is not right because i receive this message error:

HTTP/1.1 500 Internal Server Error
Server: gSOAP/2.7 Content-Type:
text/xml; charset=utf-8
Content-Length: 570 Connection: close

SOAP-ENV:VersionMismatchSOAP
version mismatch or invalid SOAP
message

I need to send this parameter to the another system :

strSOAP += " <ns:getValue>";

strSOAP += " <ns:options></ns:options>";

strSOAP += " <ns:path>/.sysinfo/.vendor-name</ns:path>";

strSOAP += " </ns:getValue>";

How i could do that in Java ?

Best regards,
Valter Henrique.

  • 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-22T02:32:58+00:00Added an answer on May 22, 2026 at 2:32 am

    If you insist on using sockets to transmit data, you’ll have to look at the SOAP specifications. For example, SOAP 1.1 requires the SOAPAction HTTP header. Use a tool like soapUI to check the validity of requests before you start writing code.

    In general, you’d be better off using an existing client API (of which there are a few to choose). For example, you can easily use hand-crafted soap requests with JAX-WS.

    A couple of notes:


    The code leaks resources. Close your streams. See the try/finally pattern.


    BufferedWriter wr = new BufferedWriter(
                         new OutputStreamWriter(sock.getOutputStream(), "UTF-8"));
    //...
    wr.write("Content-Length: " + strSOAP.length() + "\r\n");
    

    This would not be safe for code points above U+007F as String.length() returns the number of code units in UTF-16. Content-Length should contain the length in bytes; not Java chars.

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

Sidebar

Related Questions

No related questions found

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.