点击这里给我发消息 点击这里给我发消息

java调用webservice实例

添加时间:2013-12-7
    相关阅读: 相关内容

Java代码

import java.util.LinkedList;

import java.util.List;

import java.util.Map;

import java.util.Vector;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class MyWebServices 

{

    private String url="http://www.mxtong.net.cn/GateWay/Services.asmx";//提供接口的地址

    private String soapaction="http://tempuri.org/";   //域名,这是在server定义的


    public MyWebServices()

    {

        String UserID = "876890";

        String Account = "admin";

        String Password = "******";

        String Phones = "134********;1234";

        String Content = "hello,this is a test!这是个测试!";

        String SendTime = "2011-9-5 16:07:00";

        String SendType = "1";

        String PostFixNumber = "1";

        Service service=new Service();

        try{

            Call call=(Call)service.createCall();

            call.setTargetEndpointAddress(url);

            call.setOperationName(new QName(soapaction,"DirectSend")); //设置要调用哪个方法

            call.addParameter(new QName(soapaction,"UserID"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"Account"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"Password"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"Phones"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"Content"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"SendTime"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"SendType"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.addParameter(new QName(soapaction,"PostFixNumber"), //设置要传递的参数

                    org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);

            call.setReturnType(new QName(soapaction,"DirectSend"),Vector.class); //要返回的数据类型(自定义类型)

            

//            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//(标准的类型)

            

            call.setUseSOAPAction(true);

            call.setSOAPActionURI(soapaction + "DirectSend");    

            Vector v=(Vector)call.invoke(new Object[]{UserID,Account,Password,Phones,Content,SendTime,SendType,PostFixNumber});//调用方法并传递参数        

            for(int i=0;i<v.size();i++)

            {

                System.out.println(v.get(i));

            }            

        }catch(Exception ex)

        {

        ex.printStackTrace();

        }        

    }

    public static void main(String args[])

    {

        MyWebServices pw=new MyWebServices();

    }

}  

 

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册