java调.net的webservice接口的用法

package com.fbb.ap.utils;
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * SMS 工具类
 * @author Mark
 *
 */
@PropertySource(value = "classpath:fbbap.properties")
@Component
public class SmslUtil {
    
    private static String smsServerUrl = "http://10.0.0.1/service1.asmx";
     
    @Value("${fbbap.smsservurl}")
    private String mSmsServerUrl;
 
    @PostConstruct
    public void getWxUtil() {
        smsServerUrl = this.mSmsServerUrl;
    }
 
    public static String getFilePath() {
        // lockie.zou
        return smsServerUrl;
    }
    private static String methodName = "SendSMS";
    private static String userName = "BI";
    private static String systemName ="FUBAOBAO";
    private static final Logger log = LoggerFactory.getLogger("adminLogger");
    
    public static String sendSMS(String mobilePhone,String content) {
        String ret = "";
        Service service = new Service();
        String namespaceURL="http://tempuri.org/";
        try {
            Call call = (Call)service.createCall();  //通过service创建call对象
            call.setTargetEndpointAddress(new java.net.URL(smsServerUrl+"?wsdl")); //设置service所在URL
            call.setOperationName(new QName(namespaceURL,methodName));
            call.addParameter(new QName(namespaceURL,"userName"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName(namespaceURL,"systemName"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName(namespaceURL,"phonenumbers"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName(namespaceURL,"contents"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setUseSOAPAction(true);
            Object[] c={userName,systemName,mobilePhone,content};
            String result = (String)call.invoke(c);  //从这一步直接跳到System.out.println(e.toString());
            System.out.println(result);
            ret = result;
            } 
        catch (Exception e) {
                //log.error("sendSMS error:" + e.toString());
                 System.out.println(e.toString());
            }
            return ret;
    }
    
}

ap层

  /**
     * 功能:基于sms短信接口的发送
     * @author dev3
     * @param  sms
     * 
     * */
    @PostMapping("/send")
    @ResponseBody
    public String send(@RequestBody Sms sms) {
        String strRet="";
        String mobilePhone = sms.getMobilephone();
        String content = sms.getContent();
        smsDao.save(sms);
        strRet = SmslUtil.sendSMS(mobilePhone,content);
        return strRet;
    }

fbb层

    @PostMapping("/send")
    @ResponseBody
    public String send(@RequestBody Sms sms) {
        String mobilePhone = sms.getMobilephone();
        String content = sms.getContent();
        String requestURL="/sms/send";
        String strRet="";
        try{
            strRet = httpUtils.sendPost(requestURL, sms);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        System.out.println(strRet);
        return strRet;
    }

其中出现的问题:

org.apache.commons.discovery.tools.DiscoverSingleton

原因: 缺少 commons-discovery-0.2.jar

  1. Resolved exception caused by handler execution: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

原因:post只支持https    get只支持http

  1. java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/org.apache.axis.EngineConfigurationFactory]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.

原因:先将项目remove,然后停止服务器。到应用程序目录下部署的应用删除,然后启动服务器,搞定。

3.在第二步基础之上出现

System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP SOAPAction 的值:

原因:没有设SOAPAction的值.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

brid_fly

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值