4

java调用WebService的例子

 3 years ago
source link: https://www.cnblogs.com/tuyile006/archive/2008/03/14/1106294.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

java调用WebService的例子

网上下载Axis.jar包
放到C://lib目录下,共9个.
Snap.gif
然后在控制台执行以下命令
C:\lib
java -classpath ".;commons-logging-1.0.4.jar;axis.jar;commons-discovery-0.2.jar;jaxrpc.jar;wsdl4j-1.5.1.jar;
saaj.jar;activation.jar;mail.jar" org.apache.axis.wsdl.WSDL2Java -o "abcdefg"
http://10.10.10.111/WebService/ManageUsersService.asmx?wsdl
就会相应目录下生成相应的java类.然后把这些类拷到你的工程目录下,
把Axis的9个包加入到工程中,就可以像一般类一样调用WebService了.
调用方法:

        MsgService ms=new MsgServiceLocator();
        MsgServiceSoap msgServer=ms.getMsgServiceSoap();

String strSystemID = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";      //UAP系统ID,32位。
        String strAccessUserName = "aaa";                             //需要申请
        String strAccessPassWord = "aaa";                             //需要申请
        String strSMSurl = http://*/MsgService.asmx; //短信webService地址

SendMMSIn pIn = new SendMMSIn();                   //消息参数类
        pIn.setFromUserMobile("");                         //发送者手机
        pIn.setMobileList(new String[]{"13510985723"});   //接收手机列表
        SimpleDateFormat bartDateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        pIn.setSendTime(bartDateFormat.format(new Date(System.currentTimeMillis()))); // 发送时间

// 添加彩信内容--文字
        MMcontent mm1 = new MMcontent();
        mm1.setCharSet("UTF-8");
        String mm1Content="使用WS发送彩信!";
        mm1.setContentBytes(mm1Content.getBytes("UTF-8"));
        mm1.setContentID("text1.txt");
        mm1.setContentType(MMcontentType.TEXT); 

// 添加彩信内容--图片
        MMcontent mm2 = new MMcontent();
        mm2.setCharSet("UTF-8");
        byte[] bytes = getByteFromFile("F:\\mmsjp.jpg");
        mm2.setContentBytes(bytes);
        mm2.setContentType(MMcontentType.JPEG);
        mm2.setContentID("mmsjp.jpg");

MMcontent[] mmcs = new MMcontent[] {mm1,mm2};
        pIn.setMmsContents(mmcs);

SendMMSOutHolder pOut=new SendMMSOutHolder();
        SXTCallResultHolder result=new SXTCallResultHolder();
        msgServer.sendMMS(strSystemID, strAccessUserName, strAccessPassWord, pIn,result,pOut);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK