java控制台调用webserivce(C#写的)例子

步骤:

1、添加axis包

2、webservices中的代码

     /// <summary>
    /// BarCodeServices 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class BarCodeServices : System.Web.Services.WebService
    {
        [WebMethod]
        public string GetBarCodeInformation(string BarCode, string UserName, string PassWord)
        {

           return "XXXXXXX";

        }

       }

3、Java中的代码:

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;
public class MainClass {

public static void main(String[] args)  throws Exception{
WebServicesUsed();
}
//webservices调用例子
public static void WebServicesUsed() throws Exception
{
// 定义方法  
String method = "GetBarCodeInformation";  
// 定义服务  
Service service = new Service();  
// 测试1:调用HelloWorld方法,方法没有参数  
Call call2 = (Call) service.createCall();  
call2.setTargetEndpointAddress(new java.net.URL("http://10.2.32.64:7005/WebServices/BarCodeServices.asmx")); //weibservice地址
call2.setUseSOAPAction(true);  
call2.setReturnType(new QName("http://www.w3.org/2001/XMLSchema","string"));  
call2.setOperationName(new QName("http://tempuri.org/", method));  //webservice中namespace
call2.setSOAPActionURI("http://tempuri.org/GetBarCodeInformation");  //webservice中namespace的方法
call2.addParameter(new QName("http://tempuri.org/", "BarCode"),XMLType.XSD_STRING, ParameterMode.IN);  //参数
call2.addParameter(new QName("http://tempuri.org/", "UserName"),XMLType.XSD_STRING, ParameterMode.IN);   //参数
call2.addParameter(new QName("http://tempuri.org/", "PassWord"),XMLType.XSD_STRING, ParameterMode.IN);   //参数
String retVal2 = (String) call2.invoke(new Object[] { "8427650000468","SJYB","81e50f63" });  //参数值
System.out.println(retVal2);  
}

}

4、输出结果(json格式):

{"barcode":"8427650000468"}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值