java调用webservice接口具体怎么调用

java调用webservice接口具体怎么调用,第1张

使用>Java调用WebService可以直接使用Apache提供的axisjar自己编写代码,或者利用Eclipse自动生成WebService Client代码,利用其中的Proxy类进行调用。理论上是一样的,只不过用Eclipse自动生成代码省事些。
1、编写代码方式:
package comyuduntest;
import javarmiRemoteException;
import orgapacheaxisclientCall;
import orgapacheaxisclientService;
import orgapacheaxismessagePrefixedQName;
import orgapacheaxismessageSOAPHeaderElement;
import comcezannegoldenuserException;
import comcezannegoldenuserUserManagerServiceProxy;
import javaxxmlnamespaceQName;
import javanetMalformedURLException;
import javaxxmlrpcServiceException;
import javaxxmlsoapName;
import javaxxmlsoapSOAPException;
public class testWebService {
public static String getResult() throws ServiceException, MalformedURLException, RemoteException, SOAPException
{
//标识Web Service的具体路径
String endpoint = "WebService服务地址";
// 创建 Service实例
Service service = new Service();
// 通过Service实例创建Call的实例
Call call = (Call) servicecreateCall();
//将Web Service的服务路径加入到call实例之中
callsetTargetEndpointAddress( new javanetURL(endpoint) );//为Call设置服务的位置
// 由于需要认证,故需要设置调用的SOAP头信息。
Name headerName = new PrefixedQName( new QName("发布的wsdl里的targetNamespace里的url", "string_itemName") );
orgapacheaxismessageSOAPHeaderElement header = new SOAPHeaderElement(headerName);
headeraddTextNode( "blablabla" );
calladdHeader(header);

// SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("发布的wsdl里的targetNamespace里的url", "SoapHeader");
// soapHeaderElementsetNamespaceURI("发布的wsdl里的targetNamespace里的url");
// try
// {
// soapHeaderElementaddChildElement("string_itemName")setValue("blablabla");
// }
// catch (SOAPException e)
// {
// eprintStackTrace();
// }
// calladdHeader(soapHeaderElement);
//调用Web Service的方法
orgapacheaxisdescriptionOperationDesc oper;
orgapacheaxisdescriptionParameterDesc param;
oper = new orgapacheaxisdescriptionOperationDesc();
opersetName("opName");
param = new orgapacheaxisdescriptionParameterDesc(new javaxxmlnamespaceQName("", "arg0"), orgapacheaxisdescriptionParameterDescIN, new javaxxmlnamespaceQName(">1、下载soap
2、解压到c:\gsoap-27
3、将c:\gsoap-27下的soapcpp2exe,wsdl2hexe,stdsoap2h,stdsoap2cpp拷贝到C:\wstest\client\gsoap27目录下
4、在C:\wstest\client\gsoap27目录下执行soapcpp2 -C -x testh -I "C:/gsoap-27/gsoap/import"
5、在C:\wstest\client\gsoap27目录下执行wsdl2h -I "C:/gsoap-27/gsoap/WS" -s
-o testh >

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13381306.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-25
下一篇 2023-07-25

发表评论

登录后才能评论

评论列表(0条)

保存