您的位置:知识库 » 编程语言

.Net调用Java的WebService之亲身体验

作者: 振河  来源: 博客园  发布时间: 2010-09-14 21:51  阅读: 2184 次  推荐: 0   原文链接   [收藏]  

        前几天公司和别的网站合作,对方用Java的WebService给我们做了一个接口,我觉着既然是WebService,不管是用什么语言编写的,在asp.net工程中添加Web引用都应该得到WebService的一个代理类的。
操作步骤:
  1.新建一个asp.net Web 应用程序
  2.添加web引用,如图



  3.在工程中多了一个名叫Web References得目录,代理类就在这里存放着
  4.单击工程中的解决方案资源管理器中的显示所有文件,这是就可以看到那个代理类了,名字叫Reference.cs

  上述工作进行得非常顺利,去沏了一杯茶,回来该调用接口了,但是此时意想不到的终于发生了,居然接口没有在代理类中显示出来,这样的话那怎么调用啊,我认为他的WebService肯定是有问题,于是就电话和对方沟通,他们说没有问题,用Java调用是没有问题的,我们都测试过的。我还是郁闷,于是就静下来想了想,觉着他们的WebService不是标准的WebService,于是又给他们打电话,要求他们把程序检查一下,看是不是标准的WebService,于是他们不耐烦地检查了一下程序,问题终于出现了,就是他们的WebService写的不是很标准的,但是哪儿的问题我没有过问。
        把刚才的删除,又重新添加了一遍Web引用,这时,再看生成的代理类,OK,接口全部有了。
        这里把生成的代理类代码给大家贴出来:

//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by a tool.
//     Runtime Version: 1.1.4322.573
//
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

// 
// 此源代码是由 Microsoft.VSDesigner 1.1.4322.573 版自动生成。

// 
namespace JavaWebService {
    
using System.Diagnostics;
    
using System.Xml.Serialization;
    
using System;
    
using System.Web.Services.Protocols;
    
using System.ComponentModel;
    
using System.Web.Services;
    
    
    
/// <remarks/>
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    [System.Web.Services.WebServiceBindingAttribute(Name
="VChargeBinding", Namespace="http://csdfsn.esfig/javaservice")]
    
public class VChargeService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        
/// <remarks/>
        public VChargeService() {
            
this.Url = "https://www.csdfsn.cn/cma/javaService?wsdl";
        }

        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://csdfsn.esfig/javaservice", ResponseNamespace="http://csdfsn.esfig/javaservice")]
        [
return: System.Xml.Serialization.SoapElementAttribute("result")]
        
public string doservice(string String_1) {
            
object[] results = this.Invoke("doservice"new object[] {
                        String_1}
);
            
return ((string)(results[0]));
        }

        
        
/// <remarks/>
        public System.IAsyncResult Begindovcharge(string String_1, System.AsyncCallback callback, object asyncState) {
            
return this.BeginInvoke("doservice"new object[] {
                        String_1}
, callback, asyncState);
        }

        
        
/// <remarks/>
        public string Enddoservice(System.IAsyncResult asyncResult) {
            
object[] results = this.EndInvoke(asyncResult);
            
return ((string)(results[0]));
        }

        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://csdfsn.esfig/javaservice", ResponseNamespace="http://csdfsn.esfig/javaservice")]
        [
return: System.Xml.Serialization.SoapElementAttribute("result")]
        
public string docheck(string String_1) {
            
object[] results = this.Invoke("docheck"new object[] {
                        String_1}
);
            
return ((string)(results[0]));
        }

        
        
/// <remarks/>
        public System.IAsyncResult Begindocheck(string String_1, System.AsyncCallback callback, object asyncState) {
            
return this.BeginInvoke("docheck"new object[] {
                        String_1}
, callback, asyncState);
        }

        
        
/// <remarks/>
        public string Enddocheck(System.IAsyncResult asyncResult) {
            
object[] results = this.EndInvoke(asyncResult);
            
return ((string)(results[0]));
        }

    }

}

  可以看到,这个代理类和引用.net的WebService生成的代理类没有什么区别,此时下面的工作就和用.Net的WebService就一样了

  在此说明一下生成代理类还可以使用其它的方法,如wsdl等,最后的结果都是一样的。

0
0
 

编程语言热门文章

    编程语言最新文章

      最新新闻

        热门新闻