导航:首页 > 编程语言 > java获取webservice

java获取webservice

发布时间:2023-10-17 02:22:36

① 怎么使用java调用siebel 的webservice接口

整个过程还是比较简单的:

1、用SOAP UI工具测试你发布的东西到底是否可以执行

② 跪求一个最原始最通用的Java调用webservice的方法

再原始的也得先选个库啊,jdk里本身又没有访问webservice的库
比如commons-httpclient-3.1.jar里的HttpClient、xfire,axis,cxf等
比如,我一直是用cxf访问webservice的(不考虑提供方语言,就算是.net提供的webservice也一样)
CXF调用webservice步骤(我认为这个最简单,因为不需要你写代码)

1、下载CXF,并将cxf的bin目录加入到操作系统环境变量中(或者直接使用cmd命令进入CXF的bin文件夹
2、将wsdl文件放到某个目录下(如果没有设置环境变量,则将此wsdl文件放入CXF的bin文件夹),执行命令wsdl2java -impl xxx.xml,则生成了符合wsdl要求的服务器端代码
3、在生成好的代码里寻找xxx.xml,删除或修改掉这些代码即可(构造函数的URL属性修改为http://形式的字符串,比如http://127.0.0.1/xxx?wsdl,其他部分出现的xxx.xml全部删除)

③ Java客户端调用Webservice接口流程

给你看看以前写的获取电话号码归属地的代码的三种方法,然后你就懂了。

importjava.io.ByteArrayOutputStream;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.net.HttpURLConnection;
importjava.net.URL;

importorg.apache.commons.httpclient.HttpClient;
importorg.apache.commons.httpclient.HttpException;
importorg.apache.commons.httpclient.methods.PostMethod;

publicclassMobileCodeService{

publicvoidhttpGet(Stringmobile,StringuserID)throwsException
{
//http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=string&userID=string
URLurl=newURL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobile+"&userID="+userID);
HttpURLConnectionconn=(HttpURLConnection)url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");

if(conn.getResponseCode()==HttpURLConnection.HTTP_OK)//200
{
InputStreamis=conn.getInputStream();

=newByteArrayOutputStream();//

byte[]buf=newbyte[1024];
intlen=-1;
while((len=is.read(buf))!=-1)
{
//获取结果
arrayOutputStream.write(buf,0,len);
}

System.out.println("Get方式获取的数据是:"+arrayOutputStream.toString());
arrayOutputStream.close();
is.close();
}
}


publicvoidhttpPost(Stringmobile,StringuserID)throwsHttpException,IOException
{
//访问路径http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo
//HttpClient访问

HttpClienthttpClient=newHttpClient();
PostMethodpm=newPostMethod("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo");

pm.setParameter("mobileCode",mobile);
pm.setParameter("userID",userID);

intcode=httpClient.executeMethod(pm);
System.out.println("状态码:"+code);

//获取结果
Stringresult=pm.getResponseBodyAsString();
System.out.println("获取到的数据是:"+result);
}

publicvoidSOAP()throwsException
{
HttpClientclient=newHttpClient();

PostMethodmethod=newPostMethod("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx");

//设置访问方法的参数
method.setRequestBody(newFileInputStream("C:\soap.xml"));

method.setRequestHeader("Content-Type","text/xml;charset=utf-8");

intcode=client.executeMethod(method);
System.out.println("状态码:"+code);

//获取结果
Stringresult=method.getResponseBodyAsString();
System.out.println("获取到的数据是:"+result);
}

publicstaticvoidmain(String[]args)throwsException{
MobileCodeServicemcs=newMobileCodeService();
mcs.httpGet("18524012513","");
//mcs.httpPost("18524012513","");
//mcs.SOAP();
}
}
阅读全文

与java获取webservice相关的资料

热点内容
阿里云扫码登录服务器 浏览:970
化学基础pdf 浏览:896
51单片机晶码管 浏览:281
怎么查服务器假死原因日志在哪看 浏览:277
扫描pdf文件 浏览:926
解压密码百度云在线解压 浏览:767
传播学算法推荐 浏览:749
我的世界网络游戏如何查找服务器 浏览:257
安卓和苹果通讯录怎么互传 浏览:203
怎么打开隐私与应用加密的菜单 浏览:416
我的世界服务器小游戏的地址大全 浏览:578
在网络安全中加密安全机制提供了数据的 浏览:249
南京前端程序员私活怎么收费 浏览:981
拓扑pdf 浏览:440
如何在工行app查我的订单 浏览:214
车压缩机改电动 浏览:83
如何寻找音乐app 浏览:831
一加加密的照片 浏览:200
阿里云虚拟主机php 浏览:639
不卡点的解压视频 浏览:391