Solved

Access .Net Web services from java client

Posted on 2003-10-28
4
395 Views
Last Modified: 2010-03-31
When i executed the simple java client program
iam getting an soapexception- Server did not recognize the value of HTTP Header SOAPAction:http://tempuri.org/action/libSearch.TestText.

.Net web service is in a different machine and the java client in a different machine , both are inside the firewall. Kindly look into the code why it is giving this problem. Iam new to java and web service.
/*** Java Client Code ***/

import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.SOAPHTTPConnection;

public class tc
{

public static void main(String[] args) throws Exception
{

    URL url = new URL ("http://10.4.34.46/Kampong_lib/libSearch.asmx");

    SOAPMappingRegistry smr = new SOAPMappingRegistry ();
    StringDeserializer sd = new StringDeserializer ();
    smr.mapTypes (Constants.NS_URI_SOAP_ENC,    new QName ("", "Result"), null, null, sd);

    // create the transport and set parameters
   SOAPHTTPConnection st = new SOAPHTTPConnection();

   // build the call.
   Call call = new Call ();
   call.setSOAPTransport(st);
   call.setSOAPMappingRegistry (smr);

   call.setTargetObjectURI ("http://tempuri.org/message/");
   call.setMethodName("TestText");
   call.setEncodingStyleURI ("http://schemas.xmlsoap.org/soap/encoding/");

  Vector params = new Vector();
  //params.addElement(new Parameter("NumberOne", Double.class, "10", null));
  //params.addElement(new Parameter("NumberTwo", Double.class, "25", null));
  params.addElement(new Parameter("TextString", String.class, "I", null));
  call.setParams(params);

   Response resp = null;
   try
  {
      resp = call.invoke (url, "http://tempuri.org/action/libSearch.TestText");
  }
   catch (SOAPException e)
  {
   System.err.println("Caught SOAPException (" + e.getFaultCode () + "): " + e.getMessage ());
   return;
  }

  // check response
  if (resp != null && !resp.generatedFault())
  {
       Parameter ret = resp.getReturnValue();
      Object value = ret.getValue();

      System.out.println ("Answer--> " + value);
  }
  else
 {
    Fault fault = resp.getFault ();
    System.err.println ("Generated fault: ");
    System.out.println (" Fault Code = " + fault.getFaultCode());
    System.out.println (" Fault String = " + fault.getFaultString());
  }
}
}
/** END of JAVA Code **/


Reg .Net soap details:
SOAP
The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.

POST /Kampong_lib/libsearch.asmx HTTP/1.1
Host: 10.4.34.46
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost/kampong_lib/TestText

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestText xmlns="http://localhost/kampong_lib">
     <TextString>string</TextString>
   </TestText>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestTextResponse xmlns="http://localhost/kampong_lib">
     <TestTextResult>string</TestTextResult>
   </TestTextResponse>
</soap:Body>
</soap:Envelope>
HTTP GET
The following is a sample HTTP GET request and response. The placeholders shown need to be replaced with actual values.

GET /Kampong_lib/libsearch.asmx/TestText?TextString=string HTTP/1.1
Host: 10.4.34.46

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://localhost/kampong_lib">string</string>
HTTP POST
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.

POST /Kampong_lib/libsearch.asmx/TestText HTTP/1.1
Host: 10.4.34.46
Content-Type: application/x-www-form-urlencoded
Content-Length: length

TextString=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://localhost/kampong_lib">string</string>


Tks & Rgds
Shiva
0
Comment
Question by:Shivasw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 250 total points
ID: 9640487
From:

http://ws.apache.org/soap/faq/

-----------------
- Does Apache SOAP work with Microsoft SOAP?

Yes, but you need to install a patch to the MS SOAP package. One of the well-known interoperability problems between Apache 2.0 and MS Soap is that MS clients do not send type information with each parameter, and the Apache soap server will reject such requests.

James Snell has provided a patch adding the typing. It can be found at SOAP-WRC web site.

-----------------

Unfortunately, that link has gone...  hmmm....

There is this thread which may be of some use:

http://aspn.activestate.com/ASPN/Mail/Message/Apache-Soap-Users/736323

I think Apache expects the xsi:type parameter in each SOAP tag...  which MS SOAP doesn't give it...

If this IS the problem...  this page seems quite useful:

http://www.perfectxml.com/articles/xml/soapguide.asp

Anyway...not even sure this is the problem, so I'll stop typing ;-)

Good luck!!

Tim.
0
 

Expert Comment

by:myjcn
ID: 15072586
Has anyone found any more information on getting the above posted code to communicate with the .net web service?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 111
ejb example issues 3 89
jsp error 6 72
Java class and jar 3 61
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question