前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >soap 设置header 添加头元素 webservice wsdl

soap 设置header 添加头元素 webservice wsdl

作者头像
全栈程序员站长
发布2021-05-06 10:21:48
2.1K0
发布2021-05-06 10:21:48
举报
代码语言:javascript
复制
 

import java.net.URL;

 

import javax.xml.namespace.QName;

import javax.xml.rpc.ParameterMode;

 

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import org.apache.axis.encoding.XMLType;

 

import org.apache.axis.message.SOAPHeaderElement;

import javax.xml.soap.SOAPElement;

 

public class SendSMSZOP implements Runnable {

    public String phones = null;//adfbcc

    public String msg = null;//”测试”;

 

    public int T_count=0;

    public int tname=0;

 

    public void run() {

//        System.out.println(“[TN:”+tname+”] “+T_count);

        long s=System.currentTimeMillis();

        String r = send2ZOP(phones,msg);

        long e = System.currentTimeMillis();

        String time =(e-s)/1000==0?(e-s)+”毫秒”:(e-s)/1000+”秒”+(e-s)%1000+”毫秒”;

        System.out.println(“[TN:”+ tname+”] P:”+phones+” ST->”+time+”,R->”+r );

//        System.out.println(“ST->”+time+”,R->”+r );

    }

 

    private String send2ZOP(String phones, String msg) {

        String ret=null;

        try { 

 

            String Username = “dkfj”;

            String Password = “123456”;

            String nameSpace = “http://tempuri.org/”;

            String endPoint = “http://1.6.5.1/friend_ws/Ses.asmx”;

 

            Service service = new Service();

            Call call = null;

            call = (Call) service.createCall();

            call.setTargetEndpointAddress(new URL(endPoint));

 

            call.setOperationName(new QName(nameSpace, “SendMsg”));

            call.addParameter(new QName(nameSpace, “RNos”), XMLType.XSD_STRING,

                    ParameterMode.IN);

            call.addParameter(new QName(nameSpace, “Msg”), XMLType.XSD_STRING,

                    ParameterMode.IN);

            call.setReturnType(XMLType.XSD_STRING);

 

            call.setUseSOAPAction(true);

            call.setSOAPActionURI(“http://tempuri.org/SendMsg”);

 

            SOAPHeaderElement element = new SOAPHeaderElement(new QName(

                    nameSpace, “ValidHeader”));

            SOAPElement se = element.addChildElement(“Username”);

            se.addTextNode(Username);

            se = element.addChildElement(“Password”);

            se.addTextNode(Password);

            call.addHeader(element);

 

            ret = (String) call.invoke(new Object[] { phones, msg });

//            System.out.println(ret);

        } catch (Exception e) {

            e.printStackTrace();

        }

        return ret;

 

    }

 

}

 

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100558.html原文链接:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档