posts - 495,comments - 227,trackbacks - 0
原文地址:http://www.javaeye.com/topic/151541
在原文基础上加了点注释 呵呵。

所需jar包:
saaj.jar
wsdl4j-1.5.1.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
axis.jar

这些jar包都在axis项目下,
axis下载地址:http://ws.apache.org/axis/

java代码:
// 需导入的类
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

//              .net webService 地址
        String url="http://localhost:1246/WebSite3/Service.asmx";  
//              .net webService 命名空间
        String namespace = "http://tempuri.org/";  
//              .net webService 需调用的方法
        String methodName = "HelloWorld";  
        String soapActionURI = "http://tempuri.org/HelloWorld";  
        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);  
//              设置要调用的.net webService方法
        call.setOperationName(new QName(namespace, methodName));  
//              设置该方法的参数,temp为.net webService中的参数名称
        call.addParameter( new QName(namespace,"temp"),  
                org.apache.axis.encoding.XMLType.XSD_STRING,   
                javax.xml.rpc.ParameterMode.IN);  
//              设置该方法的返回值
        call.setReturnType(XMLType.XSD_STRING);
//              call.invoke(new Object[] { "kusix" });  中"kusix"为传入参数值
        String ret = (String) call.invoke(new Object[] { "kusix" });  
        System.out.println("返回结果---> " + ret);  


.net 代码
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service () {

        //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();
    }

    [WebMethod]
    public string HelloWorld(String temp) {
        return temp+" add by .net";
    }
    
}


posted on 2010-05-11 11:41 SIMONE 阅读(7616) 评论(2)  编辑  收藏 所属分类: AXISJAVA

FeedBack:
# re: java通过axis访问.net webService 简单例子
2011-07-22 09:30 | pengnan1111
感谢这位大哥提供了宝贵的资料!  回复  更多评论
  
# re: java通过axis访问.net webService 简单例子
2014-10-27 11:56 | 路人甲
为何kusix没打印出来?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: