开发者

JAX-WS Client Request Class

开发者 https://www.devze.com 2023-03-27 03:11 出处:网络
I\'m trying to create a soap based java client to consume a soap web service based http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL. CorbisImageSoap.java and CorbisImage.java were automaticall

I'm trying to create a soap based java client to consume a soap web service based http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL. CorbisImageSoap.java and CorbisImage.java were automatically generated from wsimport. I'm able to submit the request in the SOAPUI just fine but I'm unable to get my java client (CorbisClient.java) to work. I'm unsure what I need to do with Holder searchResultDataXML and Holder imagesXML. They look related to the response, but I'm unsure what do with these for the request as they're parameters in the Search api. Any ideas? I get "Length cannot be less than zero. Parameter name: length" when I execute my CorbisClient.java.

soap client to execute the Search method below

public class CorbisClient {
    public static void main(String[] args){
        CorbisImage service = new CorbisImage();
        CorbisImageSoap port = service.getCorbisImageSoap();
        String sessionUID="valid id";
        String eSTok="valid param";
        String sVTok="";
        String itemsPerPage="20";
        String startPosition="1";
        String imageSearchRequestDataXML="xml here";
        String imageFormatDataXML="xml here";
        Holder<String> searchResultDataXML=new Holder<String>();
        Holder<String> imagesXML=new Holder<String>();
        port.search(sessionUID, eSTok, sVTok, itemsPerPage, startPosition, imageSearchRequestDataXML, imageFormatDataXML, searchResultDataXML, imagesXML);
    }
}

CorbisImageSoap.java is the generated method that I want to execute from http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL

@WebService(name = "CorbisImageSoap", targetNamespace = "http://c1.net.corbis.com/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface CorbisImageSoap {


    /**
     * 
     * @param sVTok
     * @param sessionUID
     * @param searchResultDataXML
     * @param eSTok
     * @param imageSearchRequestDataXML
     * @param imagesXML
     * @param itemsPerPage
     * @param imageFormatDataXML
     * @param startPosition
     */
    @WebMethod(operationName = "Search", action = "http://c1.net.corbis.com/Search")
    @RequestWrapper(localName = "Search", targetNamespace = "http://c1.net.corbis.com/", className = "com.corbis.net.c1.Search")
    @ResponseWrapper(localName = "SearchResponse", targetNamespace = "http://c1.net.corbis.com/", className = "com.corbis.net.c1.SearchResponse")
    public void search(
        @WebParam(name = "sessionUID", targetNamespace = "http://c1.net.corbis.com/")
        String sessionUID,
        @WebParam(name = "eSTok", targetNamespace = "http://c1.net.corbis.com/")
        String eSTok,
        @WebParam(name = "sVTok", targetNamespace = "http://c1.net.corbis.com/")
        String sVTok,
        @WebParam(name = "itemsPerPage", targetNamespace = "http://c1.net.corbis.com/")
        String itemsPerPage,
        @WebParam(name = "startPosition", targetNamespace = "http://c1.net.corbis.com/")
        String startPosition,
        @WebParam(name = "imageSearchRequestDataXML", targetNamespace = "http://c1.net.corbis.com/")
        String imageSearchRequestDataXML,
        @WebParam(name = "imageFormatDataXML", targetNamespace = "http开发者_运维问答://c1.net.corbis.com/")
        String imageFormatDataXML,
        @WebParam(name = "searchResultDataXML", targetNamespace = "http://c1.net.corbis.com/", mode = WebParam.Mode.OUT)
        Holder<String> searchResultDataXML,
        @WebParam(name = "imagesXML", targetNamespace = "http://c1.net.corbis.com/", mode = WebParam.Mode.OUT)
        Holder<String> imagesXML);

CorbisImage.java

@WebServiceClient(name = "CorbisImage", targetNamespace = "http://c1.net.corbis.com/", wsdlLocation = "http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL")
    public class CorbisImage
        extends Service
    {

        private final static URL CORBISIMAGE_WSDL_LOCATION;
        private final static Logger logger = Logger.getLogger(com.corbis.net.c1.CorbisImage.class.getName());

        static {
            URL url = null;
            try {
                URL baseUrl;
                baseUrl = com.corbis.net.c1.CorbisImage.class.getResource(".");
                url = new URL(baseUrl, "http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL");
            } catch (MalformedURLException e) {
                logger.warning("Failed to create URL for the wsdl Location: 'http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL', retrying as a local file");
                logger.warning(e.getMessage());
            }
            CORBISIMAGE_WSDL_LOCATION = url;
        }

        public CorbisImage(URL wsdlLocation, QName serviceName) {
            super(wsdlLocation, serviceName);
        }

        public CorbisImage() {
            super(CORBISIMAGE_WSDL_LOCATION, new QName("http://c1.net.corbis.com/", "CorbisImage"));
        }

        /**
         * 
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap")
        public CorbisImageSoap getCorbisImageSoap() {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap"), CorbisImageSoap.class);
        }

        /**
         * 
         * @param features
         *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap")
        public CorbisImageSoap getCorbisImageSoap(WebServiceFeature... features) {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap"), CorbisImageSoap.class, features);
        }

        /**
         * 
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap12")
        public CorbisImageSoap getCorbisImageSoap12() {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap12"), CorbisImageSoap.class);
        }

        /**
         * 
         * @param features
         *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
         * @return
         *     returns CorbisImageSoap
         */
        @WebEndpoint(name = "CorbisImageSoap12")
        public CorbisImageSoap getCorbisImageSoap12(WebServiceFeature... features) {
            return super.getPort(new QName("http://c1.net.corbis.com/", "CorbisImageSoap12"), CorbisImageSoap.class, features);
        }

    }

SOAPUI Response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <wsu:Timestamp xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
         <wsu:Created>2011-08-10T05:04:00Z</wsu:Created>
         <wsu:Expires>2011-08-10T05:09:00Z</wsu:Expires>
      </wsu:Timestamp>
   </soap:Header>
   <soap:Body>
      <SearchResponse xmlns="http://c1.net.corbis.com/">
         <searchResultDataXML><![CDATA[<SearchResultData><SearchRequestUID Scope="Public" Type="Guid" Value="{34a38c64-5dbc-48df-8874-74d789a0dacd}"/><StartPosition Scope="Public" Type="Long" Value="1"/><EndPosition Scope="Public" Type="Long" Value="20"/><TotalHits Scope="Public" Type="Long" Value="323516"/></SearchResultData>]]></searchResultDataXML>
         <imagesXML><![CDATA[<Images><Image><ImageUID Scope="Public" Type="Guid" Value="{7f2535d0-9a41-4997-9694-0a4de569e6d9}"/><CorbisID Scope="Public" Type="String" Value="42-15534232"/><Title Scope="Public" Type="String" Value="Animal"/><CreditLine Scope="Public" Type="String" Value="© Robert Llewellyn/Corbis"/><IsRoyaltyFree Scope="Public" Type="Boolean" Value="False"/><AspectRatio Scope="Public" Type="String" Value="1.500000"/><URL128 Scope="Public" Type="String" Value="http://cachens.corbis.com/CorbisImage/thumb/15/53/42/15534232/42-15534232.jpg"/></Image></Images>]]></imagesXML>
      </SearchResponse>
   </soap:Body>
</soap:Envelope>
0

精彩评论

暂无评论...
验证码 换一张
取 消