Solved

Access .Net Web services from java client

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

615 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