簡體   English   中英

從WSDL鏈接Java訪問Web服務

[英]access web services from WSDL link java

我試圖通過提供WSDL的URL訪問WSDL中定義的Web服務。 我正在處理的特定案例是eBay的“ FindingService”。

解析WSDL之后,我將搜索所需的服務(例如“ FindingService”)。 接下來,我希望能夠通過某種客戶端使用該服務(發送關鍵字並獲取結果)。 我環顧四周,發現以下代碼被嘗試修改以用於示例。 由於我仍然不熟悉WSDL,因此我不確定如何適應它,並且不斷收到錯誤消息:未定義的端口類型:{ http:// WSDL / } face

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;


public class client{

    public static void main(String[] args) throws Exception {

    URL url = new URL("http://developer.ebay.com/webservices/finding/latest/findingservice.wsdl");

        //1st argument service URI, refer to wsdl document above
    //2nd argument is service name, refer to wsdl document above
        QName qname = new QName("http://www.ebay.com/marketplace/search/v1/services", "FindingService");

        Service service = Service.create(url, qname);


        face hello = service.getPort(face.class);

       System.out.println(hello.getHelloWorldAsString("test"));

    }

}

第二類是:

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface face{

    @WebMethod String getHelloWorldAsString(String name);

}

第三類是:

import javax.jws.WebService;

//Service Implementation
@WebService(endpointInterface = "face")
public class endp implements face{

    @Override
    public String getHelloWorldAsString(String name) {
        return "Hello World JAX-WS " + name;
    }

}

如果能得到一些指導,我將不勝感激。 是否可以訪問類似的服務,還是我必須使用ebay API(帶有密鑰等)?

WSDL只是客戶端和服務器之間的合同。

最好的解決方案不是在運行時解析WSDL,而是嘗試調用操作。 您可能想調用這些操作來做一些有用的事情。 例如:查找所有用戶Ebay訂單。

這些操作中的每一個都有復雜的輸入和輸出。 在Java中使用SOAP Web服務的最佳解決方案通常是基於WSDL生成代碼,因此您將擁有一個功能齊全的客戶端,而無需進行過多的工作。

我可以推薦以下API:

JAX-WS: http : //www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/

Spring-WS: https//spring.io/guides/gs/standing-web-service/

軸2: https//axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM