Link to home
Start Free TrialLog in
Avatar of Zenoe
Zenoe

asked on

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 'http://schemas.xmlsoap.org/soap/encoding/'

CODE:
  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();
     //DONT KNOW IF THE STATEMENT BELOW IS CORRECT - DOUBT IT
     smr.mapTypes(Constants.NS_URI_SOAP_ENC,
     new QName("java:za.co.xxxx.benefitScheme.services.vo", "SchemeExclusionApplicabilityVO"),
     SchemeExclusionApplicabilityVO.class, beanSer, beanSer);

     call.setTargetObjectURI( urn );
     call.setMethodName( "getAllApplicableExclusionsPerDiagnosis" );
     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
     call.setSOAPMappingRegistry(smr);

     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, "" );

XML -
<!--RESPONSE.................-->
<env:Envelope  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <env:Body>
  <m:getAllApplicableExclusionsPerDiagnosisResponse    xmlns:m="http://localhost:7001/"
    env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <result     soapenc:arrayType="xsd:anyType[1]">
    <xsd:anyType      xmlns:ns100="java:za.co.xxxx.benefitScheme.services.vo"
      xsi:type="ns100:SchemeExclusionApplicabilityVO">
     <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>
    </xsd:anyType>
   </result>
  </m:getAllApplicableExclusionsPerDiagnosisResponse>
 </env:Body>
</env:Envelope>

SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of astorer
astorer

mayankeagle is absolutely right.  This is the best solution.
Avatar of Zenoe

ASKER

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("java:za.co.xxxx.benefitScheme.services.vo", "SchemeExclusionApplicabilityVO"), SchemeExclusionApplicabilityVO.class, beanSer, beanSer);

Thanks :)
>> 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.
Avatar of Zenoe

ASKER

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 :)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zenoe

ASKER

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.