axis调用两种风格的.net WebService

本文提供了使用.NET编写的RPC和Document两种风格的WebService示例代码,并展示了如何通过Java客户端进行调用。文中详细解释了SOAPAction URI的作用及如何正确设置以避免服务端无法读取请求的问题。

Rpc风格的.net服务端代码:

using System;   
using System.Collections;   
using System.ComponentModel;   
using System.Data;   
using System.Linq;   
using System.Web;   
using System.Web.Services;   
using System.Web.Services.Protocols;   
using System.Xml.Linq;   
  
namespace WebService1   
{       
       
    [WebService(Namespace = "http://tempuri.org/")]   
    public class Service1 : System.Web.Services.WebService   
    {   
  
        [WebMethod]   
        [SoapRpcMethod(Action = "http://tempuri.org/hello", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]   
  
        public string hello(String s)   
        {   
            return "Hello,"+s;   
        }   
    }   
}  

 

 

Document风格的.net服务端代码:

namespace WebService1   
{       
       
    [WebService(Namespace = "http://tempuri.org/")]   
    public class Service1 : System.Web.Services.WebService   
    {   
  
        [WebMethod]           
        public string hello(String s)   
        {   
            return "Hello,"+s;   
        }   
    }   
}  

 

java客户端代码:

String url="http://localhost:1117/Service1.asmx";   
String namespace = "http://tempuri.org/";   
String methodName = "hello";   
String soapActionURI = "http://tempuri.org/hello";   
Service service = new Service();   
Call call = (Call) service.createCall();   
call.setTargetEndpointAddress(new java.net.URL(url));   
call.setUseSOAPAction(true);   
//这个地方没设对就会出现Server was unable to read request的错误   
call.setSOAPActionURI(soapActionURI);   
call.setOperationName(new QName(namespace, methodName));   
/*
这里如果设置成call.addParameter(new QName(namespace,"s"), XMLType.XSD_STRING,ParameterMode.IN);就是调用document风格的.net服务端如果设反了,.net服务端就接不到参数,接到的是null  
*/  
call.addParameter("s", XMLType.XSD_STRING, ParameterMode.IN);   
call.setReturnType(XMLType.XSD_STRING);   
String ret = (String) call.invoke(new Object[] { "kusix" });   
System.out.println("返回结果---> " + ret);  

 

 

如果.net在提供Rpc服务时设置成:[SoapRpcMethod(Action = "",.....  的话,那java客户端中意向的两句可以省略。

 

call.setUseSOAPAction(true);   
call.setSOAPActionURI(soapActionURI);  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值