Solved

Access .Net Web services from java client

Posted on 2003-10-28
4
391 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to open debugger port in Intellij idea 6 140
groovy example issue 10 89
nextBoolean(double p) for Random class 3 35
javap not working 8 36
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now