CXF 调用C#.net的WebService

原文链接:http://hi.baidu.com/pengfeiiw/blog/item/3203e29065aa3a8aa977a4d0.html

1.编写C#.net的WebService

Service.cs

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://localhost:9000/webservices/")]
public class Service : System.Web.Services.WebService
{
    public Service () {

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

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    
}

Service.asmx

<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" class="Service" %>

然后开户服务器(注意开启Terminal Services服务)

2.写java客户端

package demo.hw.client;

import demo.hw.server.HelloWorld;
import java.lang.reflect.Method;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;

import org.apache.cxf.frontend.ClientProxyFactoryBean;

public final class Client {

    private Client() {
    }

    public static void main(String args[]) throws Exception {

 DynamicClientFactory dcf = DynamicClientFactory.newInstance();   
   org.apache.cxf.endpoint.Client client = dcf.createClient("http://localhost:1475/ddd/Service.asmx?wsdl");   
   Object reply = client.invoke("HelloWorld", new Object[]{});
   Object[] replys=(Object[])reply;
   for(Object o:replys){
    System.out.println(o);
   }
    }

}

CXF 调用C#.net的WebService,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。