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 Todd Grinnell <te...@opentext.com> on 2005/05/13 17:52:40 UTC

Axis newbie, .NET idiot; add web reference of wsdl file generating errors? SOAP header params how-to?

I have two questions that I hope y'all can help me with. Here's a little background on why I'm bothering y'all. We've got a bunch of java interfaces being used via RMI, now we want to expose them via web services, too. We do our own authentication, so I was thinking the easiest thing is to have the client call the authentication method, and then pass the resulting authentication token as a header arg-that way the existing java interfaces don't need to change.

Question 1) I'm also not such a smartie about wsdl. (I'm sure you're wondering if I'm a smartie about anything ;-) ) The WSDL for my service is below. It works just fine with WSDL2Java, and the generated Java client stubs do just what I want them to. However, when I Add Web Reference in .NET, it gives an error, "the element attribute is not allowed on encoded message parts". If I change the part specification from "<wsdl:part element="intf:authToken" name="auth_header"/>" to "<wsdl:part type="intf:authToken" name="auth_header"/>", it says "The datatype 'authToken' is missing.", and WSDL2Java says the same thing. If I undo that change and change the operation to be literal, then it says that "The combination of style=rpc with use=literal is not supported." If I change it to style=document, it says "Unable to import operation 'getExchangeRate'. Specified cast is not valid."

Would someone take pity on the noob and help me with my WSDL? 

Question 2) I know virtually nothing about c#, but someone gave me a test program that calls a web service.  I was able to figure out how to add my web service to the environment, and add a call to it from the little program, but what do I do about header args? Could someone help me figure how to pass a SOAP header argument on the call? Or will this problem be magically solved once I can successfully import the web service? Here's the code I have:

	FirstSOAPTest.CurrencyService.CurrencyWebServiceService curServ = new FirstSOAPTest.CurrencyService.CurrencyWebServiceService();
	// The value of a proper authToken is in this.textBoxAuthReturn.Text
	double s = curServ.getExchangeRate();


The WSDL is what was generated by Axis, and then I added the bits about a header arg (the parts I added are surrounded by blank lines). Here's my WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
    targetNamespace="http://localhost:8080/avalanche/services/currency"
    xmlns:impl="http://localhost:8080/avalanche/services/currency"
    xmlns:intf="http://localhost:8080/avalanche/services/currency"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <!-- added by me -->    
    <wsdl:types>
        <xsd:schema
            targetNamespace="http://localhost:8080/avalanche/services/currency"
            xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xsd1="http://localhost:8080/avalanche/services/.xsd1">
            <xsd:element name="authToken">
                <xsd:complexType>
                    <xsd:all>
                        <xsd:element maxOccurs="1" minOccurs="1" name="value" type="xsd:string"/>
                    </xsd:all>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <!-- end addition -->    

    <!-- added by me -->    
    <wsdl:message name="getExchangeRateRequest">
        <wsdl:part type="intf:authToken" name="auth_header"/>
    </wsdl:message>
    <!-- end addition -->    

    <wsdl:message name="getExchangeRateResponse">
        <wsdl:part name="getExchangeRateReturn" type="xsd:double"/>
    </wsdl:message>
    <wsdl:portType name="CurrencyWebService">
        <wsdl:operation name="getExchangeRate">
            <wsdl:input message="impl:getExchangeRateRequest" name="getExchangeRateRequest"/>
            <wsdl:output
                message="impl:getExchangeRateResponse"
                name="getExchangeRateResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="currencySoapBinding" type="impl:CurrencyWebService">
        <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

        <!-- added by me -->    
        <wsdl:operation name="getExchangeRate">
            <wsdlsoap:operation soapAction=""/>
            <wsdl:input name="getExchangeRateRequest">
                <wsdlsoap:body 
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="http://currency.examples.ecm.opentext.com" 
                    use="encoded"/>
                <wsdlsoap:header
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    message="impl:getExchangeRateRequest"
                    part="auth_header"
                    use="encoded"/>
            </wsdl:input>
            <wsdl:output name="getExchangeRateResponse">
                <wsdlsoap:body
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="urn:http://localhost:8080/avalanche/services/currency"
                    use="encoded"/>
            </wsdl:output>
        </wsdl:operation>
        <!-- end addition -->  
  
    </wsdl:binding>
    <wsdl:service name="CurrencyWebServiceService">
        <wsdl:port binding="impl:currencySoapBinding" name="currency">
            <wsdlsoap:address location="http://localhost:8080/avalanche/services/currency"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>



--
'Peace is not merely a distant goal that we seek, but a means by which we arrive at that goal' Dr. M. L. King, Jr.
Todd Grinnell ( mailto:teg@opentext.com ) Open Text Corp. Chicago 'burbs, IL Contact me for a public key
  


Re: Axis newbie, .NET idiot; add web reference of wsdl file generating errors? SOAP header params how-to?

Posted by Anne Thomas Manes <at...@gmail.com>.
Todd, 

SOAP Headers are supposed to be defined as document/literal. Axis
doesn't support mix and match of soap messages (header in doc/literal
and body in rpc/encoded), so it's best to just use doc/literal when
using soap headers. On top of that, if you want to interoperate with
.NET you should use the "wrapped" convention.

Here's an updated version of your WSDL defined using the "wrapped" convention:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
   targetNamespace="http://localhost:8080/avalanche/services/currency"
   xmlns:impl="http://localhost:8080/avalanche/services/currency"
   xmlns:intf="http://localhost:8080/avalanche/services/currency"
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
   xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">

   <!-- added by me -->
   <wsdl:types>
       <xsd:schema
           targetNamespace="http://localhost:8080/avalanche/services/currency"
           xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xmlns:xsd1="http://localhost:8080/avalanche/services/.xsd1">
           <xsd:element name="authToken">
               <xsd:complexType>
                   <xsd:all>
                       <xsd:element maxOccurs="1" minOccurs="1"
name="value" type="xsd:string"/>
                   </xsd:all>
               </xsd:complexType>
           </xsd:element>

           <!-- wrapper elements added by ATM -->
           <xsd:element name="getExchangeRate">
              <xsd:complexType>
                 <xsd:sequence/>
              </xsd:complexType>
           </xsd:element>
           <xsd:element name="getExchangeRateResponse">
              <xsd:complexType>
                 <xsd:sequence>
                    <xsd:element name="getExchangeRateReturn"
type="xsd:double"/>
                 </xsd:sequence>
              </xsd:complexType>
           </xsd:element>
           <!-- end ATM addition -->

       </xsd:schema>
   </wsdl:types>
   <!-- end addition -->

   <!-- added by me -->
   <wsdl:message name="getExchangeRateRequest">
       <!-- ATM changed "type" to "element" -->
       <wsdl:part element="intf:authToken" name="auth_header"/>
       <!-- body part added by ATM -->
       <wsdl:part name="parameters" element="intf:getExchangeRate"/>
       <!-- end ATM addition -->
   </wsdl:message>
   <!-- end addition -->

   <wsdl:message name="getExchangeRateResponse">
       <!-- ATM changed name to "parameters" and changed "type" to "element" -->
       <wsdl:part name="parameters" element="intf:getExchangeRateResponse"/>
   </wsdl:message>
   <wsdl:portType name="CurrencyWebService">
       <wsdl:operation name="getExchangeRate">
           <wsdl:input message="impl:getExchangeRateRequest"
name="getExchangeRateRequest"/>
           <wsdl:output
               message="impl:getExchangeRateResponse"
               name="getExchangeRateResponse"/>
       </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="currencySoapBinding" type="impl:CurrencyWebService">
       <!-- ATM changed to style="document" -->
       <wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>

       <!-- added by me -->
       <wsdl:operation name="getExchangeRate">
           <wsdlsoap:operation soapAction=""/>
           <wsdl:input name="getExchangeRateRequest">
               <!-- ATM changed bindings to literal -->
               <wsdlsoap:body parts="parameters" use="literal"/>
               <wsdlsoap:header
                   message="impl:getExchangeRateRequest"
                   part="auth_header"
                   use="literal"/>
           </wsdl:input>
           <wsdl:output name="getExchangeRateResponse">
               <wsdlsoap:body use="literal"/>
           </wsdl:output>
       </wsdl:operation>
       <!-- end addition -->

   </wsdl:binding>
   <wsdl:service name="CurrencyWebServiceService">
       <wsdl:port binding="impl:currencySoapBinding" name="currency">
           <wsdlsoap:address
location="http://localhost:8080/avalanche/services/currency"/>
       </wsdl:port>
   </wsdl:service>
</wsdl:definitions>


On 5/13/05, Todd Grinnell <te...@opentext.com> wrote:
> I have two questions that I hope y'all can help me with. Here's a little background on why I'm bothering y'all. We've got a bunch of java interfaces being used via RMI, now we want to expose them via web services, too. We do our own authentication, so I was thinking the easiest thing is to have the client call the authentication method, and then pass the resulting authentication token as a header arg-that way the existing java interfaces don't need to change.
> 
> Question 1) I'm also not such a smartie about wsdl. (I'm sure you're wondering if I'm a smartie about anything ;-) ) The WSDL for my service is below. It works just fine with WSDL2Java, and the generated Java client stubs do just what I want them to. However, when I Add Web Reference in .NET, it gives an error, "the element attribute is not allowed on encoded message parts". If I change the part specification from "<wsdl:part element="intf:authToken" name="auth_header"/>" to "<wsdl:part type="intf:authToken" name="auth_header"/>", it says "The datatype 'authToken' is missing.", and WSDL2Java says the same thing. If I undo that change and change the operation to be literal, then it says that "The combination of style=rpc with use=literal is not supported." If I change it to style=document, it says "Unable to import operation 'getExchangeRate'. Specified cast is not valid."
> 
> Would someone take pity on the noob and help me with my WSDL?
> 
> Question 2) I know virtually nothing about c#, but someone gave me a test program that calls a web service.  I was able to figure out how to add my web service to the environment, and add a call to it from the little program, but what do I do about header args? Could someone help me figure how to pass a SOAP header argument on the call? Or will this problem be magically solved once I can successfully import the web service? Here's the code I have:
> 
>         FirstSOAPTest.CurrencyService.CurrencyWebServiceService curServ = new FirstSOAPTest.CurrencyService.CurrencyWebServiceService();
>         // The value of a proper authToken is in this.textBoxAuthReturn.Text
>         double s = curServ.getExchangeRate();
> 
> The WSDL is what was generated by Axis, and then I added the bits about a header arg (the parts I added are surrounded by blank lines). Here's my WSDL:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <wsdl:definitions
>     targetNamespace="http://localhost:8080/avalanche/services/currency"
>     xmlns:impl="http://localhost:8080/avalanche/services/currency"
>     xmlns:intf="http://localhost:8080/avalanche/services/currency"
>     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
>     xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
>     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> 
>     <!-- added by me -->
>     <wsdl:types>
>         <xsd:schema
>             targetNamespace="http://localhost:8080/avalanche/services/currency"
>             xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
>             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>             xmlns:xsd1="http://localhost:8080/avalanche/services/.xsd1">
>             <xsd:element name="authToken">
>                 <xsd:complexType>
>                     <xsd:all>
>                         <xsd:element maxOccurs="1" minOccurs="1" name="value" type="xsd:string"/>
>                     </xsd:all>
>                 </xsd:complexType>
>             </xsd:element>
>         </xsd:schema>
>     </wsdl:types>
>     <!-- end addition -->
> 
>     <!-- added by me -->
>     <wsdl:message name="getExchangeRateRequest">
>         <wsdl:part type="intf:authToken" name="auth_header"/>
>     </wsdl:message>
>     <!-- end addition -->
> 
>     <wsdl:message name="getExchangeRateResponse">
>         <wsdl:part name="getExchangeRateReturn" type="xsd:double"/>
>     </wsdl:message>
>     <wsdl:portType name="CurrencyWebService">
>         <wsdl:operation name="getExchangeRate">
>             <wsdl:input message="impl:getExchangeRateRequest" name="getExchangeRateRequest"/>
>             <wsdl:output
>                 message="impl:getExchangeRateResponse"
>                 name="getExchangeRateResponse"/>
>         </wsdl:operation>
>     </wsdl:portType>
>     <wsdl:binding name="currencySoapBinding" type="impl:CurrencyWebService">
>         <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
> 
>         <!-- added by me -->
>         <wsdl:operation name="getExchangeRate">
>             <wsdlsoap:operation soapAction=""/>
>             <wsdl:input name="getExchangeRateRequest">
>                 <wsdlsoap:body
>                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>                     namespace="http://currency.examples.ecm.opentext.com"
>                     use="encoded"/>
>                 <wsdlsoap:header
>                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>                     message="impl:getExchangeRateRequest"
>                     part="auth_header"
>                     use="encoded"/>
>             </wsdl:input>
>             <wsdl:output name="getExchangeRateResponse">
>                 <wsdlsoap:body
>                     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>                     namespace="urn:http://localhost:8080/avalanche/services/currency"
>                     use="encoded"/>
>             </wsdl:output>
>         </wsdl:operation>
>         <!-- end addition -->
> 
>     </wsdl:binding>
>     <wsdl:service name="CurrencyWebServiceService">
>         <wsdl:port binding="impl:currencySoapBinding" name="currency">
>             <wsdlsoap:address location="http://localhost:8080/avalanche/services/currency"/>
>         </wsdl:port>
>     </wsdl:service>
> </wsdl:definitions>
> 
> --
> 'Peace is not merely a distant goal that we seek, but a means by which we arrive at that goal' Dr. M. L. King, Jr.
> Todd Grinnell ( mailto:teg@opentext.com ) Open Text Corp. Chicago 'burbs, IL Contact me for a public key
> 
> 
>