java調用wsdl xfire和cxf兩種方式


     xfire 如下:
       String spID = ""; String password = ""; String accessCode = ""; String content = ""; String mobileString = ""; String url = ""; String operateName = "Submit"; Object[] object = new Object[]{spID,password,accessCode,content,mobileString}; org.codehaus.xfire.client.Client client = new org.codehaus.xfire.client.Client(new URL(url)); String a = client.getUrl(); Object[] results = client.invoke(operateName, object); System.out.println("aaaa:" + results[0]);


cxf

        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        Client client = factory.createClient(url);

        // 下面一段處理 WebService接口和實現類namespace不同的情況 

        // CXF動態客戶端在處理此問題時,會報No operation was found with the name的異常
        Endpoint endpoint = client.getEndpoint();
        QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), operateName);
        BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
        if (bindingInfo.getOperation(opName) == null) {
        for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
        if (operateName.equals(operationInfo.getName().getLocalPart())) {
            opName = operationInfo.getName();
            break;
            }
          }
        }

      Object[] res = client.invoke(opName, object);





 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM