java 調用webservcie ,自己親測可用

來源:互聯網
上載者:User

標籤:soa   http   encoding   package   namespace   cti   cli   imp   ESS   

 第一次用 java 調webervice,網上看了很多部落格,能用的沒幾個,綜合幾個部落格,終於成功調用了。

 

 

package com.casco.action;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

 

public class syncProjectData {

public void syncProject(String projectNo)
{

}

public static void main(String[] args) {
try {
String endpoint = "XXXX?wsdl";
// 直接引用遠端wsdl檔案
// 以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("http://tempuri.org/","GetProjectByCondition")); // WSDL裡面描述的介面名稱
call.addParameter(new QName("http://tempuri.org/","condition"),
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);// 介面的參數
call.setUseSOAPAction(true);
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); //返回參數的類型
call.setSOAPActionURI("http://tempuri.org/GetProjectByCondition"); //這個也要注意 就是要加上要調用的方法GetProjectByCondition,不然也會報錯
String temp = "A0117032"; //參數的值
String result = (String) call.invoke(new Object[] { temp });
// 給方法傳遞參數,並且調用方法
System.out.println("result is " + result);
} catch (Exception e) {
System.err.println(e.toString());
}

}
}

java 調用webservcie ,自己親測可用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.