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);
?? }
??? }
}
轉載于:https://www.cnblogs.com/hqbhonker/p/3876077.html
總結
以上是生活随笔為你收集整理的CXF 调用C#.net的WebService的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: source insight常用命令--
- 下一篇: C# GridView单元格合并.