You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Håkon T Sønderland <ht...@antares.no> on 2005/12/06 14:18:31 UTC

Creating a WS client, where to start?

<<< Newbie Alert!!!! >>>
<<< Newbie Alert!!!! >>>
<<< Newbie Alert!!!! >>>

Sorry about the total newbie questions.

I am trying to use Axis to create a WS client consuming an
existing web service.

I've read all the newbie tutorial I could find, but the all seem
to be on the "hello world" level and think I understand what they
do.  But, trying to this with the web service I need, I get very
confused.

I'm using Axis 1.2.1 and Java 1.4.

I generate the client code using WSDL2Java such:

java org.apache.axis.wsdl.WSDL2Java -t -s \ 
"https://www.creditinform.biz/CreditInform.StandardWebservice.WS2005207/InfoXML.asmx?wsdl"

I now get among the stuff here a class called Header, which contains
username, password etc.

I think this should be used for setting up the username etc.  But how?

I generated the JUnit test class (-t parameter) hoping it would give me
a clue as to how to use the Header class, but it does not reference it
at all.  Needless to say none of the tutorial have anything like this.

Help?

Pointers to examples for WS clients (beyond "hello world") would be much
appreciated.

Thanks,
Håkon
-- 
We shall fight on the beaches,
we shall fight on the landing grounds,
we shall fight in the fields and in the streets,
we shall fight in the hills;
we shall never surrender
http://www.getfirefox.com/

Re: Creating a WS client, where to start?

Posted by Håkon T Sønderland <ht...@antares.no>.
Dies Koper wrote:
> Hello Håkon,
> 
> pretty please does help. Did you look at Axis' JUnit tests?
> 
> test\wsdl\stubheaders

Do you mean the JUnit tests that WSDL2Java generates with the
-t option? If so, then yes I did look at them, there is no reference
to the header there.

In my limited view of the world the WSDL2Java ought to have generated
stubs where the "Header" object is a parameter to the methods (this
according to the FAQ).  This does not happen (it seems).

I checked with a tool I downloaded (Stylus free trial) which seems
to understand where the header goes so I was able to test that the
web-service I try to use works.

I think I'll try something like this:

Header header
    = new Header(user,pass,subuser,custid,version);
InfoXML service = new InfoXMLLocator();
InfoXMLSoap port = service.getInfoXMLSoap();
Stub stub = (Stub)port;
stub.setHeader("https://www.creditinform.no/creditinform.standardwebservice.ws2005207/InfoXML","Header",header);
ReportPersonResponseReportPersonResult person
   = port.reportPerson("", strSocSecNumber, "", "", "", "", "");
MessageElement[] message = person.get_any();

Does this look like it could work?

Håkon

-- 
We shall fight on the beaches,
we shall fight on the landing grounds,
we shall fight in the fields and in the streets,
we shall fight in the hills;
we shall never surrender
http://www.getfirefox.com/

Re: Creating a WS client, where to start?

Posted by Dies Koper <di...@jp.fujitsu.com>.
Hello Håkon,

pretty please does help. Did you look at Axis' JUnit tests?

test\wsdl\stubheaders

Regards,
Dies


Håkon T Sønderland wrote:
> Håkon T Sønderland wrote:
> 
>>
>> I am trying to use Axis to create a WS client consuming an
>> existing web service.
>>
>> I've read all the newbie tutorial I could find, but the all seem
>> to be on the "hello world" level and think I understand what they
>> do.  But, trying to this with the web service I need, I get very
>> confused.
>>
>> I'm using Axis 1.2.1 and Java 1.4.
>>
>> I generate the client code using WSDL2Java such:
>>
>> java org.apache.axis.wsdl.WSDL2Java -t -s \ 
>> "https://www.creditinform.biz/CreditInform.StandardWebservice.WS2005207/InfoXML.asmx?wsdl" 
>>
>>
>> I now get among the stuff here a class called Header, which contains
>> username, password etc.
>>
>> I think this should be used for setting up the username etc.  But how?
>>
>> I generated the JUnit test class (-t parameter) hoping it would give me
>> a clue as to how to use the Header class, but it does not reference it
>> at all.  Needless to say none of the tutorial have anything like this.
>>
> 
> OK, noone wanted to answer this so here is what I've found so far.
> 
> The Axis FAQ says:
> 
> "How do I set a header when using WSDL2Java stubs?
> 
>     There are two styles of headers, explicit and implicit. Explicit 
> headers are defined in the WSDL of the service. The WSDL2Java generation 
> tool will recognize these headers in most cases and emit stub class 
> methods that include the headers as arguments to the methods.
> 
>     In other cases, you may want to set headers that are not explicitly 
> called out in the WSDL. For instance, you want to do some custom 
> processing in a handler or add security. In this case you can add
> headers to request before you invoke the stub method."
> 
> What happens here is that the WSDL has information on the header, thus:
> 
>       <s:element name="Header" type="tns:Header"/>
>       <s:complexType name="Header">
>         <s:sequence>
>           <s:element minOccurs="0" maxOccurs="1" name="UserName" 
> type="s:string"/>
>           <s:element minOccurs="0" maxOccurs="1" name="Password" 
> type="s:string"/>
>           <s:element minOccurs="0" maxOccurs="1" name="SubUser" 
> type="s:string"/>
>           <s:element minOccurs="0" maxOccurs="1" name="CustomerId" 
> type="s:string"/>
>           <s:element minOccurs="0" maxOccurs="1" name="Version" 
> type="s:string"/>
>         </s:sequence>
>       </s:complexType>
>       </s:element>
> 
> this is referenced later:
> 
>   <wsdl:message name="ReportPersonSoapIn">
>     <wsdl:part name="parameters" element="tns:ReportPerson"/>
>   </wsdl:message>
>   <wsdl:message name="ReportPersonSoapOut">
>     <wsdl:part name="parameters" element="tns:ReportPersonResponse"/>
>   </wsdl:message>
>   <wsdl:message name="ReportPersonHeader">
>     <wsdl:part name="Header" element="tns:Header"/>
>   </wsdl:message>
> 
> However WSDL2Java does not "emit stub class methods that include the
> headers as arguments to the methods" as the FAQ suggests.
> 
> Question: Is there anything wrong with the WSDL?
> (the WSDL validates btw)
> 
> Does it help if I say pretty please?
> 
> Håkon
> 


Re: Creating a WS client, where to start?

Posted by Håkon T Sønderland <ht...@antares.no>.
Håkon T Sønderland wrote:
> 
> I am trying to use Axis to create a WS client consuming an
> existing web service.
> 
> I've read all the newbie tutorial I could find, but the all seem
> to be on the "hello world" level and think I understand what they
> do.  But, trying to this with the web service I need, I get very
> confused.
> 
> I'm using Axis 1.2.1 and Java 1.4.
> 
> I generate the client code using WSDL2Java such:
> 
> java org.apache.axis.wsdl.WSDL2Java -t -s \ 
> "https://www.creditinform.biz/CreditInform.StandardWebservice.WS2005207/InfoXML.asmx?wsdl" 
> 
> 
> I now get among the stuff here a class called Header, which contains
> username, password etc.
> 
> I think this should be used for setting up the username etc.  But how?
> 
> I generated the JUnit test class (-t parameter) hoping it would give me
> a clue as to how to use the Header class, but it does not reference it
> at all.  Needless to say none of the tutorial have anything like this.
> 

OK, noone wanted to answer this so here is what I've found so far.

The Axis FAQ says:

"How do I set a header when using WSDL2Java stubs?

     There are two styles of headers, explicit and implicit. Explicit 
headers are defined in the WSDL of the service. The WSDL2Java generation 
tool will recognize these headers in most cases and emit stub class 
methods that include the headers as arguments to the methods.

     In other cases, you may want to set headers that are not explicitly 
called out in the WSDL. For instance, you want to do some custom 
processing in a handler or add security. In this case you can add
headers to request before you invoke the stub method."

What happens here is that the WSDL has information on the header, thus:

       <s:element name="Header" type="tns:Header"/>
       <s:complexType name="Header">
         <s:sequence>
           <s:element minOccurs="0" maxOccurs="1" name="UserName" 
type="s:string"/>
           <s:element minOccurs="0" maxOccurs="1" name="Password" 
type="s:string"/>
           <s:element minOccurs="0" maxOccurs="1" name="SubUser" 
type="s:string"/>
           <s:element minOccurs="0" maxOccurs="1" name="CustomerId" 
type="s:string"/>
           <s:element minOccurs="0" maxOccurs="1" name="Version" 
type="s:string"/>
         </s:sequence>
       </s:complexType>
       </s:element>

this is referenced later:

   <wsdl:message name="ReportPersonSoapIn">
     <wsdl:part name="parameters" element="tns:ReportPerson"/>
   </wsdl:message>
   <wsdl:message name="ReportPersonSoapOut">
     <wsdl:part name="parameters" element="tns:ReportPersonResponse"/>
   </wsdl:message>
   <wsdl:message name="ReportPersonHeader">
     <wsdl:part name="Header" element="tns:Header"/>
   </wsdl:message>

However WSDL2Java does not "emit stub class methods that include the
headers as arguments to the methods" as the FAQ suggests.

Question: Is there anything wrong with the WSDL?
(the WSDL validates btw)

Does it help if I say pretty please?

Håkon