JAX-WS客户端请求类

时间:2011-08-10 05:33:24

标签: soap jax-ws

我正在尝试创建一个基于soap的java客户端来使用基于http://api2.corbis.com/WSCorbisOne/CorbisImage.asmx?WSDL的soap web服务。 CorbisImageSoap.java和CorbisImage.java是从wsimport自动生成的。我能够在SOAPUI中提交请求就好了,但我无法让我的Java客户端(CorbisClient.java)工作。我不确定我需要用Holder searchResultDataXML和Holder imagesXML做什么。它们看起来与响应有关,但我不确定如何处理这些请求,因为它们是Search api中的参数。有任何想法吗?当我执行CorbisClient.java时,我得到“长度不能小于零。参数名称:长度”。

soap客户端执行下面的搜索方法

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是我想要从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响应:

<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 个答案:

没有答案