views:

396

answers:

2

I have a web service that returns a dataset object that contains the current weather forecast along with 0 or more weather alerts for a county/state. The dataset object just contains a Weather object and an array of Alerts objects. One of the clients of this would like to have it so the response gives the weather first instead of the alerts. Is there a way to specify the order of the response elements? I thought I could just change the WSDL to map out the weather first then the alerts, but that didn't do anything.

Here's the generic WSDL sheet:
(well, it showed formatted in the preview but not after posting... how can I post formatted XML on here? I tried using back-ticks as well as pre and code).

<wsdl:definitions ...>
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://ws.sample.com" xmlns="http://www.w3.org/2001/XMLSchema"&gt;
   <import namespace="http://objects.sample.com"/&gt;
   <element name="getAll">
    <complexType>
     <sequence>
      <element name="county" type="xsd:string"/>
      <element name="state" type="xsd:string"/>
      <element name="latitude" type="xsd:double"/>
      <element name="longitude" type="xsd:double"/>
     </sequence>
    </complexType>
   </element>
   <element name="getAllResponse">
    <complexType>
     <sequence>
      <element name="getAllReturn" type="tns1:DataSet"/>
     </sequence>
    </complexType>
   </element>
   <complexType name="ArrayOf_tns1_Alert">
    <sequence>
     <element maxOccurs="unbounded" minOccurs="0" name="item" type="tns1:Alert"/>
    </sequence>
   </complexType>
  </schema>
  <schema elementFormDefault="qualified" targetNamespace="http://objects.sample.com" xmlns="http://www.w3.org/2001/XMLSchema"&gt;
   <import namespace="http://ws.sample.com"/&gt;
   <complexType name="Alert">
    <sequence>
     <element name="county" nillable="true" type="xsd:string"/>
     <element name="endDate" nillable="true" type="xsd:dateTime"/>
     <element name="locationCode" nillable="true" type="xsd:string"/>
     <element name="startDate" nillable="true" type="xsd:dateTime"/>
     <element name="state" nillable="true" type="xsd:string"/>
     <element name="title" nillable="true" type="xsd:string"/>
     <element name="warning" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
   <complexType name="Weather">
    <sequence>
     <element name="chancePrecipitation" type="xsd:int"/>
     <element name="period" nillable="true" type="xsd:string"/>
     <element name="skyConditions" nillable="true" type="xsd:string"/>
     <element name="temperature" type="xsd:int"/>
     <element name="temperatureType" nillable="true" type="xsd:string"/>
     <element name="temperatureUnit" nillable="true" type="xsd:string"/>
     <element name="windDirection" nillable="true" type="xsd:string"/>
     <element name="windSpeed" type="xsd:int"/>
     <element name="windUnit" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
   <complexType name="DataSet">
    <sequence>
     <element name="weather" nillable="true" type="tns1:Weather"/>
     <element name="alert" nillable="true" type="impl:ArrayOf_tns1_Alert"/>
    </sequence>
   </complexType>
  </schema>
 </wsdl:types>
   <wsdl:message name="getAllResponse">
      <wsdl:part element="impl:getAllResponse" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="getAllRequest">
      <wsdl:part element="impl:getAll" name="parameters"/>
   </wsdl:message>
   <wsdl:portType name="TSTWeather">
      <wsdl:operation name="getAll">
         <wsdl:input message="impl:getAllRequest" name="getAllRequest"/>
         <wsdl:output message="impl:getAllResponse" name="getAllResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="TSTWeatherSoapBinding" type="impl:TSTWeather">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
      <wsdl:operation name="getAll">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="getAllRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="getAllResponse">
            <wsdlsoap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="TSTWeatherService">
      <wsdl:port binding="impl:TSTWeatherSoapBinding" name="TSTWeather">
         <wsdlsoap:address location="http://localhost:8282/Services/service/TSTWeather"/&gt;
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

I don't see how I could specify the order of my service response.

A: 

In many cases, just changing the WSDL does not change the service, and it's the service that determines the order of the elements in the XML.

John Saunders
Yea, I realized later that the WSDL is simply the definition for a user to build a client from. I have been trying to google JAXB and JAX-WS but I do not know what to search for... it appears the elements are just listed alphabetically in most cases.
ravun
I was going to say huh?!? until I realized that you had also written a comment on the OP. I think that comment needs to be rolled into your answer, because a service that doesn't follow its WSDL is a broken service.
kdgregory
A: 

I am having the same issue presented here.

I am utilising Tomcat 5.5 and Axis 1.4. Created Java classes from WSDL code and proceeded to deploy on Tomcat., then progressed to utilise soapUI as a client-side test.

My issue is slightly different but very much so related.

I am wanting to match an output sample i have, but i am receving a slightly different soap response and I am not sure what to do.

This is the code i am trying to match to.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
 <soapenv:Body>
  <ns1:creditCardManualPaymentUResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="test.pay.mill.com">
   <receiptDetails href="#id0"/>
   <transactionResultU href="#id1"/>
  </ns1:creditCardManualPaymentUResponse>
  <multiRef id="id1" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:TransactionResultU" xmlns:ns2="test.pay.mill.com">
   <responseCode xsi:type="xsd:string">0</responseCode>
   <responseText xsi:type="xsd:string">Successful.</responseText>
   <transactionId xsi:type="xsd:string">102</transactionId>
  </multiRef>
  <multiRef id="id0" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:ReceiptDetails" xmlns:ns3="test.pay.mill.com">
   <receipt xsi:type="xsd:string">0900057636</receipt>
   <Balance xsi:type="xsd:int">24000</Balance>
   <ExpiryDate xsi:type="xsd:string">20101210</ExpiryDate>
  </multiRef>
 </soapenv:Body>
</soapenv:Envelope>

And this is what i am seeing through soapUI,

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
   <soapenv:Body>
      <ns1:creditCardManualPaymentUResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="test.pay.mill.com">
         <receiptDetails href="#id0"/>
         <transactionResultU href="#id1"/>
      </ns1:creditCardManualPaymentUResponse>
      <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:TransactionResultU" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="test.pay.mill.com">
         <responseCode xsi:type="xsd:string">test again</responseCode>
         <responseText xsi:type="xsd:string">Successful</responseText>
         <transactionId xsi:type="xsd:string">13</transactionId>
      </multiRef>
      <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:ReceiptDetails" xmlns:ns3="test.pay.mill.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"&gt;
         <receipt xsi:type="xsd:string">1571018999</receipt>
         <Balance href="#id2"/>
         <ExpiryDate xsi:type="xsd:string">20120101</ExpiryDate>
      </multiRef>
      <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"&gt;432&lt;/multiRef&gt;
   </soapenv:Body>
</soapenv:Envelope>

Notice how there is an extra multiRef created for the Balance variable in the soapUI response. Any ideas what needs to be done to obtain a response that matches the first code?

Thanks for reading, colpwd

colpwd