Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

Apache SOAP: Quick example

Hi all,

       Im trying to call a web-service through Java. The service is implemented remotely in c#.  There are two methods implemented remotely, each of which both takes a String as an argument and returns a String as a result.

Here's what im looking for: A quick, no-bull (simple/short as possible) example of the Java code required to call the remote method (called sayHello(), for example) and get the result, to then print to the screen.

Lets say that the service is located at:
http://192.168.0.50/service/myservice.asmx

i.e.

import org.apache.soap;
..etc;
class QuickTest
{
    public static void main(String args[])
    {

        String value="John";

        //...code here
   
       String result = ?.?()
       System.out.println(result);
    }
}

I gotta say, im not looking to learn the ins and outs of SOAP at the moment but im finding it very difficult to find anything as simple as 'heres how to call a method at http://xxx/xxx/ and retireve the result, now go have fun!'...which is all i need at the moment. I have wasted alot of time allready trying to access my c# code through JNI (shudder).

-T.I.A.
0
eoin2000
Asked:
eoin2000
3 Solutions
 
CEHJCommented:
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mayank SAssociate Director - Product EngineeringCommented:
Download WSDL 2 Java from Apache Axis:

http://ws.apache.org/axis/java/reference.html 

http://ws.apache.org/axis/java/ant/axis-wsdl2java.html 

It will help you create proxies/ stubs for the web-service using:

java org.apache.axis.wsdl.WSDL2Java <web-service URL>

The proxies/ stubs will be Java classes of which you can create objects locally and call their methods - they will result in calls to the actual web-service. You don't need to worry about serialization/ de-serialization of parameters and return-value.
0
 
eoin2000Author Commented:
Right: After alot of fannying about with classpaths and such...

CEHJ:
I used your second example (the shorter one).  This is exactly the kind of thing i was looking for. Alas, I cant get it to run.  When I run the code, I get the following Exception:

System.Web.Services.Protocols.SoapException: Server did not recognise the value of HTTP Header SOAPAction.

My understanding of this header is that its not vital, and only really serves to differentiate the http request as being a soap request (so as a firewall can filter them, for example...)?  Is this the case, do you know? And could i possibly yank it out of the request?
0
 
eoin2000Author Commented:
Here be my code:

public static void main(String args[])
      {
            
            try
            {    

      String soapurl ="http://192.168.0.52/Encryptor.asmx";
       
      Call call = (Call) (new Service()).createCall();

      call.setTargetEndpointAddress( new java.net.URL(soapurl) );
      call.setOperationName(new QName("", "encryptPassword"));

      call.addParameter("original", XMLType.XSD_STRING, ParameterMode.IN);
      call.setReturnType(XMLType.SOAP_STRING);

      String ts = (String) call.invoke(new Object[] {"a-string-value"});    
      System.out.println(ts);

    } catch (Exception e) {
      System.err.println(e.toString());
    }
      }
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now