原文链接: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