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

热点内容
数据库查询系统源码 浏览:614
php5314 浏览:354
完美国际安装到哪个文件夹 浏览:666
什么app可以扫一扫做题 浏览:537
程序员编码论坛 浏览:923
淘点是什么app 浏览:658
中国高等植物pdf 浏览:453
51单片机时间 浏览:181
后台如何获取服务器ip 浏览:265
单片机流水灯程序c语言 浏览:232
程序员第二职业挣钱 浏览:237
运行里怎么输入服务器路径 浏览:840
pythonstepwise 浏览:509
刘一男词汇速记指南pdf 浏览:62
php认证级别 浏览:366
方舟编译啥时候推送 浏览:1010
php手机验证码生成 浏览:675
哲学思维pdf 浏览:14
凌达压缩机有限公司招聘 浏览:534
weblogic命令部署 浏览:36