Axis调用.NET中的Web Service

工程实践的子系统涉及到了点Axis调用ASP.NET开发的Web Service的方法,小结一下。

1- 使用.NET开发一个Web Service,并将接口写为如下方式:

    [SoapRpcMethod(Action  =   " http://www.wsscore.com/isStudentLoginSuccessful/Rpc " , RequestNamespace  =   " http://www.wsscore.com/isStudentLoginSuccessful/SU " , ResponseNamespace  =   " http://www.my.com/isStudentLoginSuccessful/SU " )]
    [WebMethod]
    
public   int  isStudentLoginSuccessful( string  studentID,  string  password)
    
{
        BasicStudentInfo bs 
= new BasicStudentInfo();
        
// 1:successful   0:wrong password   -1:no such studentID
        return bs.isLoginSuccessful(studentID,password);
    }

 注意[SoapRpcMethod]属性是比较重要的,涉及到RPC方式调用的Action和名字空间。

2- 使用Axis调用这个Web服务的接口:


public   class  DotNetWSScore  {
    
public DotNetWSScore(){}
    
    
public int isLoginSuccessful(String studentID, String password){
        
try {
            ResourceBundle rb
=ResourceBundle.getBundle("com.wsscore4student.business.service-config");
            String endpoint
= rb.getString("url");
            System.out.println( 
"url is " + endpoint);
            Service service 
= new Service();
            Call call 
= (Call)service.createCall();
            call.setTargetEndpointAddress(
new java.net.URL(endpoint));
            call.setOperationName(
new QName("http://www.wsscore.com/isStudentLoginSuccessful/SU","isStudentLoginSuccessful"));
            call.addParameter(
"studentID",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN);
            call.addParameter(
"password",org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
            call.setUseSOAPAction(
true);
            call.setSOAPActionURI(
"http://www.wsscore.com/isStudentLoginSuccessful/Rpc");
            
int k = (Integer)call.invoke(new Object[]{studentID,password});
            System.out.println( 
"result is " + k + ".");
            
return k;
        }

        
catch (Exception e) {System.err.println(e.toString());}
        
return -1;
    }

}

这里我把发布.NET Web服务的url放在了com.wsscore4student.business.service-config.properties里面,本地包里的一个属性文件而已~ 动态读取,方便配置~

现在就可以实现Axis对.NET Web Service的调用了。

希望对大家有些用。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值