Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access .Net Web services from java client

Posted on 2003-10-28
4
Medium Priority
?
397 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 1000 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

664 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