Java Client to call Weblogic WebService

Hi guys,

I have a webservice that is deployed, running and working on a Weblogic Server (lets for now use my localhost and port 7001).

I want to create a simple client in Java to test it (not just test, but also use the info that it returns). I used the same code on another service and it worked, but this service accepts a string and returns a string - easy.

My webservice returns a List of objects. The objects are of a type that I defined as SchemeExclusionApplicabilityVO. I read that I need to use the "MapTypes" and "QName" methods in order to define my types, but I can't get it right. I don't know where to look up the values to pass as parameters. I have the wsdl file and also the xml that gets returned as result. Pasted my test code below. Also an extract of the result xml.

This is the error that I get:
SOAP-ENV:Client, No Deserializer found to deserialize a ':result' using encoding style ''

  URL url = new URL( "http://localhost:7001/XXX/ExclusionService/ChronicExclusionService" );
     String urn = "urn:demo1:exchange"; //NOT SURE OF THIS ONE - LEFT IT LIKE THE EXAMPLE I FOUND
     Call call = new Call();
     SOAPMappingRegistry smr = new SOAPMappingRegistry();
     BeanSerializer beanSer = new BeanSerializer();
     new QName("", "SchemeExclusionApplicabilityVO"),
     SchemeExclusionApplicabilityVO.class, beanSer, beanSer);

     call.setTargetObjectURI( urn );
     call.setMethodName( "getAllApplicableExclusionsPerDiagnosis" );

     Vector params = new Vector();
     params.addElement( new Parameter( "string", String.class, "80000", Constants.NS_URI_SOAP_ENC ) );
     params.addElement( new Parameter( "string0", String.class, "0", Constants.NS_URI_SOAP_ENC ) );
     params.addElement( new Parameter( "string1", String.class, "7777", Constants.NS_URI_SOAP_ENC ) );
     params.addElement( new Parameter( "string2", String.class, "20060610", Constants.NS_URI_SOAP_ENC ) );
     call.setParams( params );
    Response response = call.invoke( url, "" );

<env:Envelope  xmlns:env=""
  <m:getAllApplicableExclusionsPerDiagnosisResponse    xmlns:m="http://localhost:7001/"
   <result     soapenc:arrayType="xsd:anyType[1]">
    <xsd:anyType      xmlns:ns100=""
     <definitePossibleFlag       xsi:type="xsd:string">P</definitePossibleFlag>
     <exclusionType       xsi:type="xsd:string">37</exclusionType>
     <exclusionTypeDescription       xsi:type="xsd:string">An Exclusions</exclusionTypeDescription>
     <reasonCode       xsi:type="xsd:string">3145</reasonCode>
     <reasonDescription       xsi:type="xsd:string">This is a descr</reasonDescription>

Who is Participating?

Improve company productivity with a Business Account.Sign Up

astorerConnect With a Mentor Commented:
Looking at your code, you use  SOAPMappingRegistry and  BeanSerializer. Can you check what packages they are in?

I think you might find that they are Apache Axis.  It would appear that you are already using Apache Axis but maybe not in the best way.  The best way to use Axis (or any soap toolkit) on the client side is:
1. start with the WSDL from your server
2. run it through a tool such as WSDL2Java (Axis gives that to you) - this generates mappings XML to/from java and a clientside stub.  That stub looks after all (de)serialization for you.
3. call that client stub.

You don't need to worry about any code involving serializers or Map Types.
good luck
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
I would use WSDL 2 Java from Apache Axis and create proxy/ stubs for the web-service. Then create a stub object and call its methods locally like any normal object/ method, it will result in calls to the web-service and will take care of serialization/ de-serialization itself.
mayankeagle is absolutely right.  This is the best solution.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

ZenoeAuthor Commented:
Hi guys,

Thanks for the reply, but even though I read somewhere else that this might be the fastest way, I don't think it will work in my situation. Firstly, the environment I am working in - I can't just use any other technology, it is not just my own application where I can pick and choose. Then I also had a very quick read through this site and what it does. I am not sure whether the fact that it recreates the objects locally is such a viable solution in my case (does it regenerate the source locally?), as the people who owns this webservice might change it at any time (without me being notified). Doesn't that mean that my service will be incorrect until I regenerate the code?

If anyone knows, I basically need to know what to pass to the following statements in the case of a LIST of objects being returned (Can I get the parameter values from the wsdl or result soap message?):

1) String urn = "urn:demo1:exchange";

2) smr.mapTypes(Constants.NS_URI_SOAP_ENC,
     new QName("", "SchemeExclusionApplicabilityVO"), SchemeExclusionApplicabilityVO.class, beanSer, beanSer);

Thanks :)
Mayank SAssociate Director - Product EngineeringCommented:
>> I can't just use any other technology

The technology being recommended is from Apache and is also free of cost, and its used in production systems too. Instead of you handling the serialization/ de-serialization of messages, you are letting it handle all that for you - and its tried/ tested.
ZenoeAuthor Commented:
mayankeagle, I didn't mean the statement in a negative light. After your posts I read up a bit on it, but unfortunately it is not my call. The environment I am involved in is much larger than me and to get the decision made by the right people will take too long. I was hoping to solve this thing quickly. The code that I posted is suppose to solve the problem according to a couple of sites and forums on the internet, but I cannot figure out where to get the precise values to pass to the mapping methods. If there is no other way, I can probably put a suggestion forward to the "powers that be", but I am still curious as to the correct usage of the above mentioned code :)
ZenoeAuthor Commented:
I don't fully agree with the point split. I feel that my question hasn't been adequately answered. I never wanted to know how to create a webservice client, I wanted to know how the code that I posted works when dealing with complex types. I tried to bring this across everytime - it might not have been the ideal solution, but in the environment I was coding this is what I wanted to do. I know it can work, because I tried it on a simple type. I appreciate the input from mayankeagle & astorer, but I didn't get the information I needed. Any other suggestions?
It appears to me your question has been answered.  If you want to consume web services , use Apache Axis.  It appears (from some of your posts) that you are using it, but then you appear to be using it incorrectly.

So, the answer is that if you want complex types in your interface, use Apache Axis correctly.

If you insist that you have no choice there and that you will use Axis in a way that it was not designed, then the next investigation is to look how Apache Axis handles complex types.  You can find that level of information:
 - in the classes generated by Axis's WSDL2Java
 - in the WSDD (the deployment descriptor) generated by Axis's WSDL2Java

This is non trivial.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.