导航:首页 > 编程语言 > 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相关的资料

热点内容
vmwaretoolslinux 浏览:91
命令方块生存放不了吗 浏览:697
程序员入门很难吗 浏览:101
70后程序员照片 浏览:192
一个普通程序员能干多久 浏览:936
adobe的PDF转换器 浏览:860
单片机数字码表汇编 浏览:485
单片机开发用的软件 浏览:158
程序员8个算法题 浏览:402
php题库系统 浏览:227
王牌战争文明重启选什么服务器 浏览:659
简述对称加密法 浏览:664
c语言数学编程 浏览:997
F1B命令 浏览:630
cs命令快捷键 浏览:852
阿里云购买服务器如何用现金支付 浏览:697
pythontime等待 浏览:995
单片机串行通信方式 浏览:505
android表格demo 浏览:284
安卓怎么让相册不显示网页 浏览:321