web services - How to use the User Defined Datatypes found in the WSDL file in our java code? -


i trying consume remote web service using wsimport tool. generates necessary client side code. in found return type of method user defined using xml complex type. how can use complex types in java code. here code try

import net.restfulwebservices.servicecontracts._2008._01.weatherforecastservice; import net.restfulwebservices.servicecontracts._2008._01.iweatherforecastservice; import com.microsoft.schemas._2003._10.serialization.arrays.arrayofstring; public class weatherforecastclient  {      public static void main(string args[])throws     net.restfulwebservices.servicecontracts._2008._01.iweatherforecastservicegetcitiesbycountrydefaultfaultcontractfaultfaultmessage     {         try         {             weatherforecastservice wf=new weatherforecastservice();             iweatherforecastservice iw=wf. getbasichttpbindingiweatherforecastservice();             arrayofstring as=new arrayofstring();             as=iw.getcitiesbycountry("us");             system.out.println(as);         }         catch(exception e)         {             e.printstacktrace();         }     } } 

in arrayofstring user defined type. found file named arrayofstring contains following code.

    package com.microsoft.schemas._2003._10.serialization.arrays;  import java.util.arraylist;     import java.util.list;     import javax.xml.bind.annotation.xmlaccesstype;     import javax.xml.bind.annotation.xmlaccessortype;     import javax.xml.bind.annotation.xmlelement;     import javax.xml.bind.annotation.xmltype;     /**     * <p>java class arrayofstring complex type.     *      * <p>the following schema fragment specifies expected content contained within class.     *      * <pre>     * &lt;complextype name="arrayofstring">     *   &lt;complexcontent>     *     &lt;restriction base="{http://www.w3.org/2001/xmlschema}anytype">     *       &lt;sequence>     *         &lt;element name="string" type="{http://www.w3.org/2001/xmlschema}string" maxoccurs="unbounded" minoccurs="0"/>     *       &lt;/sequence>     *     &lt;/restriction>     *   &lt;/complexcontent>     * &lt;/complextype>     * </pre>     *      *      */     @xmlaccessortype(xmlaccesstype.field)     @xmltype(name = "arrayofstring", proporder = {     "string"     })     public class arrayofstring {      @xmlelement(nillable = true)     protected list<string> string;      /**      * gets value of string property.      *       * <p>      * accessor method returns reference live list,      * not snapshot. therefore modification make      * returned list present inside jaxb object.      * why there not <code>set</code> method string property.      *       * <p>      * example, add new item, follows:      * <pre>      *    getstring().add(newitem);      * </pre>      *       *       * <p>      * objects of following type(s) allowed in list      * {@link string }      *       *       */     public list<string> getstring() {         if (string == null) {             string = new arraylist<string>();         }         return this.string;     } 

when executing code got following exceptions

 javax.xml.ws.webserviceexception         @ com.sun.xml.internal.ws.model.runtimemodel.createjaxbcontext(unknown source)         @ com.sun.xml.internal.ws.model.runtimemodel.postprocess(unknown source )         @ com.sun.xml.internal.ws.modeler.runtimemodeler.buildruntimemodel(unkn own source)         @ com.sun.xml.internal.ws.client.servicecontextbuilder.processannotatio ns(unknown source)         @ com.sun.xml.internal.ws.client.servicecontextbuilder.completeservicec ontext(unknown source)         @ com.sun.xml.internal.ws.client.wsservicedelegate.processservicecontex t(unknown source)         @ com.sun.xml.internal.ws.client.wsservicedelegate.createendpointifbase proxy(unknown source)         @ com.sun.xml.internal.ws.client.wsservicedelegate.getport(unknown sour ce)         @ javax.xml.ws.service.getport(unknown source)         @ net.restfulwebservices.servicecontracts._2008._01.weatherforecastserv ice.getbasichttpbindingiweatherforecastservice(weatherforecastservice.java:50)         @ weatherforecastclient.main(weatherforecastclient.java:12)     caused by: com.sun.xml.internal.bind.v2.runtime.illegalannotationsexception: 5 c ounts of illegalannotationexceptions     there's no objectfactory @xmlelementdecl element {http://www.res tfulwebservices.net/servicecontracts/2008/01}country.     problem related following location:                 @ protected javax.xml.bind.jaxbelement net.restfulwebservices.s ervicecontracts._2008._01.getcitiesbycountry.country                 @ net.restfulwebservices.servicecontracts._2008._01.getcitiesby country     there's no objectfactory @xmlelementdecl element {http://www.res tfulwebservices.net/servicecontracts/2008/01}getcitiesbycountryresult.         problem related following location:                 @ protected javax.xml.bind.jaxbelement net.restfulwebservices.s ervicecontracts._2008._01.getcitiesbycountryresponse.getcitiesbycountryresult                 @ net.restfulwebservices.servicecontracts._2008._01.getcitiesby countryresponse     there's no objectfactory @xmlelementdecl element {http://www.res tfulwebservices.net/servicecontracts/2008/01}city.         problem related following location:                 @ protected javax.xml.bind.jaxbelement net.restfulwebservices.s ervicecontracts._2008._01.getforecastbycity.city                 @ net.restfulwebservices.servicecontracts._2008._01.getforecast bycity     there's no objectfactory @xmlelementdecl element {http://www.res tfulwebservices.net/servicecontracts/2008/01}country.         problem related following location:                 @ protected javax.xml.bind.jaxbelement net.restfulwebservices.s ervicecontracts._2008._01.getforecastbycity.country                 @ net.restfulwebservices.servicecontracts._2008._01.getforecast bycity     there's no objectfactory @xmlelementdecl element {http://www.res tfulwebservices.net/servicecontracts/2008/01}getforecastbycityresult.         problem related following location:                 @ protected javax.xml.bind.jaxbelement net.restfulwebservices.s ervicecontracts._2008._01.getforecastbycityresponse.getforecastbycityresult                 @ net.restfulwebservices.servicecontracts._2008._01.getforecast bycityresponse          @ com.sun.xml.internal.bind.v2.runtime.illegalannotationsexception$buil der.check(unknown source)         @ com.sun.xml.internal.bind.v2.runtime.jaxbcontextimpl.gettypeinfoset(u nknown source)         @ com.sun.xml.internal.bind.v2.runtime.jaxbcontextimpl.<init>(unknown s ource)         @ com.sun.xml.internal.bind.v2.contextfactory.createcontext(unknown sou rce)         @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)         @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)         @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)         @ java.lang.reflect.method.invoke(unknown source)         @ com.sun.xml.internal.bind.api.jaxbricontext.newinstance(unknown sourc e)         @ com.sun.xml.internal.ws.model.runtimemodel$1.run(unknown source)         @ java.security.accesscontroller.doprivileged(native method)         ... 11 more 

anyone can give suggestions why exception occured.thanks in advance

wsdl file

 <wsdl:definitions name="weatherforecastservice" targetnamespace="http://www.restfulwebservices.net/servicecontracts/2008/01">                     <wsdl:types>         <xsd:schema targetnamespace="http://www.restfulwebservices.net/servicecontracts/2008/01/imports">     <xsd:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd0" namespace="http://www.restfulwebservices.net/servicecontracts/2008/01"/>     <xsd:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd3" namespace="http://gotlservices.faultcontracts/2008/01"/>     <xsd:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/serialization/"/>     <xsd:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/serialization/arrays"/>     <xsd:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd4" namespace="http://www.restfulwebservices.net/datacontracts/2008/01"/>     </xsd:schema>     </wsdl:types>     <wsdl:message name="iweatherforecastservice_getcitiesbycountry_inputmessage">         <wsdl:part name="parameters" element="tns:getcitiesbycountry"/></wsdl:message>       <wsdl:message name="iweatherforecastservice_getcitiesbycountry_outputmessage">      <wsdl:part name="parameters" element="tns:getcitiesbycountryresponse"/></wsdl:message>      <wsdl:message name="iweatherforecastservice_getcitiesbycountry_defaultfaultcontractfault_faultmessage">     <wsdl:part name="detail" element="q1:defaultfaultcontract"/></wsdl:message>     <wsdl:message name="iweatherforecastservice_getforecastbycity_inputmessage"><wsdl:part name="parameters" element="tns:getforecastbycity"/></wsdl:message>     <wsdl:message name="iweatherforecastservice_getforecastbycity_outputmessage">        <wsdl:part name="parameters" element="tns:getforecastbycityresponse"/></wsdl:message>       <wsdl:message name="iweatherforecastservice_getforecastbycity_defaultfaultcontractfault_faultmessage">       <wsdl:part name="detail" element="q2:defaultfaultcontract"/></wsdl:message>     <wsdl:porttype name="iweatherforecastservice"><wsdl:operation name="getcitiesbycountry">     <wsdl:input wsaw:action="getcitiesbycountry" message="tns:iweatherforecastservice_getcitiesbycountry_inputmessage"/>     <wsdl:output wsaw:action="http://www.restfulwebservices.net/servicecontracts/2008/01/iweatherforecastservice/getcitiesbycountryresponse" message="tns:iweatherforecastservice_getcitiesbycountry_outputmessage"/>     <wsdl:fault wsaw:action="http://www.restfulwebservices.net/servicecontracts/2008/01/iweatherforecastservice/getcitiesbycountrydefaultfaultcontractfault" name="defaultfaultcontractfault" message="tns:iweatherforecastservice_getcitiesbycountry_defaultfaultcontractfault_faultmessage"/></wsdl:operation>     <wsdl:operation name="getforecastbycity">     <wsdl:input wsaw:action="getforecastbycity" message="tns:iweatherforecastservice_getforecastbycity_inputmessage"/>     <wsdl:output wsaw:action="http://www.restfulwebservices.net/servicecontracts/2008/01/iweatherforecastservice/getforecastbycityresponse" message="tns:iweatherforecastservice_getforecastbycity_outputmessage"/>     <wsdl:fault wsaw:action="http://www.restfulwebservices.net/servicecontracts/2008/01/iweatherforecastservice/getforecastbycitydefaultfaultcontractfault" name="defaultfaultcontractfault" message="tns:iweatherforecastservice_getforecastbycity_defaultfaultcontractfault_faultmessage"/>     </wsdl:operation>     </wsdl:porttype>     <wsdl:binding name="basichttpbinding_iweatherforecastservice" type="tns:iweatherforecastservice">     <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>     <wsdl:operation name="getcitiesbycountry"><soap:operation soapaction="getcitiesbycountry" style="document"/>     <wsdl:input><soap:body use="literal"/></wsdl:input>     <wsdl:output><soap:body use="literal"/></wsdl:output>     <wsdl:fault name="defaultfaultcontractfault"><soap:fault name="defaultfaultcontractfault" use="literal"/></wsdl:fault></wsdl:operation>        <wsdl:operation name="getforecastbycity"><soap:operation soapaction="getforecastbycity" style="document"/>     <wsdl:input><soap:body use="literal"/></wsdl:input>     <wsdl:output><soap:body use="literal"/></wsdl:output>     <wsdl:fault name="defaultfaultcontractfault"><soap:fault name="defaultfaultcontractfault" use="literal"/></wsdl:fault></wsdl:operation>        </wsdl:binding>     <wsdl:service name="weatherforecastservice">     <wsdl:port name="basichttpbinding_iweatherforecastservice" binding="tns:basichttpbinding_iweatherforecastservice">     <soap:address location="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc"/>     </wsdl:port>     </wsdl:service>     </wsdl:definitions> 

xsd file0

<xs:schema elementformdefault="qualified" targetnamespace="http://www.restfulwebservices.net/servicecontracts/2008/01"> <xs:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/serialization/arrays"/> <xs:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd4" namespace="http://www.restfulwebservices.net/datacontracts/2008/01"/> <xs:element name="getcitiesbycountry"> <xs:complextype> <xs:sequence> <xs:element minoccurs="0" name="country" nillable="true" type="xs:string"/>     </xs:sequence> </xs:complextype> </xs:element> <xs:element name="getcitiesbycountryresponse"> <xs:complextype> <xs:sequence> <xs:element minoccurs="0" name="getcitiesbycountryresult" nillable="true" type="q1:arrayofstring"/> </xs:sequence> </xs:complextype> </xs:element> <xs:element name="getforecastbycity"> <xs:complextype> <xs:sequence> <xs:element minoccurs="0" name="city" nillable="true" type="xs:string"/> <xs:element minoccurs="0" name="country" nillable="true" type="xs:string"/>    </xs:sequence> </xs:complextype> </xs:element>  <xs:element name="getforecastbycityresponse"> <xs:complextype><xs:sequence><xs:element minoccurs="0" name="getforecastbycityresult" nillable="true" type="q2:weather"/> </xs:sequence> </xs:complextype>  </xs:element> </xs:schema>  

xsd file1

<xs:schema attributeformdefault="qualified" elementformdefault="qualified" targetnamespace="http://schemas.microsoft.com/2003/10/serialization/"> <xs:element name="anytype" nillable="true" type="xs:anytype"/> <xs:element name="anyuri" nillable="true" type="xs:anyuri"/> <xs:element name="base64binary" nillable="true" type="xs:base64binary"/> <xs:element name="boolean" nillable="true" type="xs:boolean"/> <xs:element name="byte" nillable="true" type="xs:byte"/> <xs:element name="datetime" nillable="true" type="xs:datetime"/> <xs:element name="decimal" nillable="true" type="xs:decimal"/> <xs:element name="double" nillable="true" type="xs:double"/> <xs:element name="float" nillable="true" type="xs:float"/> <xs:element name="int" nillable="true" type="xs:int"/> <xs:element name="long" nillable="true" type="xs:long"/> <xs:element name="qname" nillable="true" type="xs:qname"/> <xs:element name="short" nillable="true" type="xs:short"/> <xs:element name="string" nillable="true" type="xs:string"/> <xs:element name="unsignedbyte" nillable="true" type="xs:unsignedbyte"/> <xs:element name="unsignedint" nillable="true" type="xs:unsignedint"/> <xs:element name="unsignedlong" nillable="true" type="xs:unsignedlong"/> <xs:element name="unsignedshort" nillable="true" type="xs:unsignedshort"/> <xs:element name="char" nillable="true" type="tns:char"/> <xs:simpletype name="char"> <xs:restriction base="xs:int"/></xs:simpletype> <xs:element name="duration" nillable="true" type="tns:duration"/> <xs:simpletype name="duration"> <xs:restriction base="xs:duration"> <xs:pattern value="\-?p(\d*d)?(t(\d*h)?(\d*m)?(\d*(\.\d*)?s)?)?"/><xs:mininclusive value="-p10675199dt2h48m5.4775808s"/> <xs:maxinclusive value="p10675199dt2h48m5.4775807s"/> </xs:restriction> </xs:simpletype> <xs:element name="guid" nillable="true" type="tns:guid"/> <xs:simpletype name="guid"> <xs:restriction base="xs:string"> <xs:pattern value="[\da-fa-f]{8}-[\da-fa-f]{4}-[\da-fa-f]{4}-[\da-fa-f]{4}-[\da-fa-f]{12}"/> </xs:restriction> </xs:simpletype> <xs:attribute name="factorytype" type="xs:qname"/> <xs:attribute name="id" type="xs:id"/> <xs:attribute name="ref" type="xs:idref"/> </xs:schema> 

xsd file2

 <xs:schema elementformdefault="qualified" targetnamespace="http://schemas.microsoft.com/2003/10/serialization/arrays">     <xs:complextype name="arrayofstring">  <xs:sequence>  <xs:element minoccurs="0" maxoccurs="unbounded" name="string" nillable="true" type="xs:string"/>  </xs:sequence>  </xs:complextype><xs:element name="arrayofstring" nillable="true" type="tns:arrayofstring"/>  </xs:schema> 

xsd file3

<xs:schema elementformdefault="qualified" targetnamespace="http://gotlservices.faultcontracts/2008/01"> <xs:import schemalocation="http://www.restfulwebservices.net/wcf/weatherforecastservice.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/serialization/"/> <xs:complextype name="defaultfaultcontract"> <xs:sequence> <xs:element name="errorid" type="xs:int"/> <xs:element name="errormessage" nillable="true" type="xs:string"/> <xs:element name="correlationid" type="ser:guid"/> </xs:sequence> </xs:complextype> <xs:element name="defaultfaultcontract" nillable="true" type="tns:defaultfaultcontract"/> </xs:schema> 

some jaxb versions doesn't support same element name , type name in xsd.

you should have 2 different names element , type.

     <xs:schema elementformdefault="qualified" targetnamespace="http://schemas.microsoft.com/2003/10/serialization/arrays">     <xs:complextype name="arrayofstring">  <xs:sequence>  <xs:element minoccurs="0" maxoccurs="unbounded" name="string" nillable="true" type="xs:string"/>  </xs:sequence>  </xs:complextype><xs:element name="arrayofstring" nillable="true" type="tns:arrayofstring"/>  </xs:schema> 

in above xsd both complex type name , element type name "arrayofstring". may cause above exception. please try generate web service client changing xsd follows.

    <xs:schema elementformdefault="qualified" targetnamespace="http://schemas.microsoft.com/2003/10/serialization/arrays">     <xs:complextype name="arrayofstringtype">  <xs:sequence>  <xs:element minoccurs="0" maxoccurs="unbounded" name="string" nillable="true" type="xs:string"/>  </xs:sequence>  </xs:complextype><xs:element name="arrayofstring" nillable="true" type="tns:arrayofstringtype"/>  </xs:schema> 

need change other xsd files too.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -