Java Client to call Weblogic WebService

Posted on 2006-06-15
Last Modified: 2012-06-22
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>

Question by:Zenoe
  • 3
  • 3
  • 2
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 65 total points
ID: 16911020
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.

Expert Comment

ID: 16918212
mayankeagle is absolutely right.  This is the best solution.

Author Comment

ID: 16932015
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 :)
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 30

Expert Comment

by:Mayank S
ID: 16932030
>> 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.

Author Comment

ID: 16936823
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 :)

Accepted Solution

astorer earned 65 total points
ID: 16938319
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

Author Comment

ID: 17120637
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?

Expert Comment

ID: 17120819
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.

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why my table column Id is not passed to java object? 4 44
type mismatch (Object[] to double[] 4 33
ejb on wildfly 5 30
java mysql insert application 14 29
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

820 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