Solved

Access .Net Web services from java client

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

757 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

23 Experts available now in Live!

Get 1:1 Help Now