Beyond the dream——飛雪飄寒

————磨難不過是人生鍵盤的回車。。。。。。
  博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

  最近,由于业务需求,项目需要调用其他单位提供的接口来同步数据,对方提供的接口是java开发的WebService,返回的数据是二维数组。我们的项目是05年开发的.net1.1版本,在调用对方接口获取返回的二维数组数据时,提示“XML 文档(1, 378)中有错误”。经测试无论在哪个框架下添加引用对方服务时,生成的CS文件返回的都是一维数组,而并非二维数组,在.net2.0以上版本,强制性修改CS文件的方法来返回二维数组可以得到对方的数据,但在.net1.1版本,强制性修改CS文件的方法来返回二维数组时就提示“XML 文档(1, 378)中有错误”。上google搜索该问题,部分网友说.net1.1调用WebService不支持二维数组,不知道是否真是这样,如果支持二维数组,请问各位园友这个问题如何解决?期待园友的解答,谢谢!
  一、在.net1.1、.net2.0、.net3.0的测试情况具体如下:
 
 注意:修改后的CS文件主要对方法findRegisterQuota的返回类型作了修改,默认为一维数组,强制性修改为二维数组了。

  1.net2.0环境  

  (1)调用对方服务生成的原始CS文件

代码
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行库版本:2.0.50727.3603
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

// 
// 此源代码是由 Microsoft.VSDesigner 2.0.50727.3603 版自动生成。
// 
#pragma warning disable 1591

namespace WebApplication2.WebReference {
    
using System.Diagnostics;
    
using System.Web.Services;
    
using System.ComponentModel;
    
using System.Web.Services.Protocols;
    
using System;
    
using System.Xml.Serialization;
    
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    [System.Web.Services.WebServiceBindingAttribute(Name
="RegisterServiceSoapBinding", Namespace="http://register.webservice.hnisi.com.cn")]
    
public partial class RegisterService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        
private System.Threading.SendOrPostCallback registerOperationCompleted;
        
        
private System.Threading.SendOrPostCallback findRegisterQuotaOperationCompleted;
        
        
private bool useDefaultCredentialsSetExplicitly;
        
        
/// <remarks/>
        public RegisterService() {
            
this.Url = global::WebApplication2.Properties.Settings.Default.WebApplication2_WebReference_RegisterService;
            
if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                
this.UseDefaultCredentials = true;
                
this.useDefaultCredentialsSetExplicitly = false;
            }
            
else {
                
this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        
public new string Url {
            
get {
                
return base.Url;
            }
            
set {
                
if ((((this.IsLocalFileSystemWebService(base.Url) == true
                            
&& (this.useDefaultCredentialsSetExplicitly == false)) 
                            
&& (this.IsLocalFileSystemWebService(value) == false))) {
                    
base.UseDefaultCredentials = false;
                }
                
base.Url = value;
            }
        }
        
        
public new bool UseDefaultCredentials {
            
get {
                
return base.UseDefaultCredentials;
            }
            
set {
                
base.UseDefaultCredentials = value;
                
this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        
/// <remarks/>
        public event registerCompletedEventHandler registerCompleted;
        
        
/// <remarks/>
        public event findRegisterQuotaCompletedEventHandler findRegisterQuotaCompleted;
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("RegisterReturn")]
        
public string[] register(string userID, string password, string[] citizenInfos) {
            
object[] results = this.Invoke("register"new object[] {
                        userID,
                        password,
                        citizenInfos});
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        public void registerAsync(string userID, string password, string[] citizenInfos) {
            
this.registerAsync(userID, password, citizenInfos, null);
        }
        
        
/// <remarks/>
        public void registerAsync(string userID, string password, string[] citizenInfos, object userState) {
            
if ((this.registerOperationCompleted == null)) {
                
this.registerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnregisterOperationCompleted);
            }
            
this.InvokeAsync("register"new object[] {
                        userID,
                        password,
                        citizenInfos}, 
this.registerOperationCompleted, userState);
        }
        
        
private void OnregisterOperationCompleted(object arg) {
            
if ((this.registerCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs 
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                
this.registerCompleted(thisnew registerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("FindRegisterQuotaReturn")]
        
public string[]findRegisterQuota(string userID, string password, string annual, string departmentCode) {
            
object[] results = this.Invoke("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode});
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        public void findRegisterQuotaAsync(string userID, string password, string annual, string departmentCode) {
            
this.findRegisterQuotaAsync(userID, password, annual, departmentCode, null);
        }
        
        
/// <remarks/>
        public void findRegisterQuotaAsync(string userID, string password, string annual, string departmentCode, object userState) {
            
if ((this.findRegisterQuotaOperationCompleted == null)) {
                
this.findRegisterQuotaOperationCompleted = new System.Threading.SendOrPostCallback(this.OnfindRegisterQuotaOperationCompleted);
            }
            
this.InvokeAsync("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode}, 
this.findRegisterQuotaOperationCompleted, userState);
        }
        
        
private void OnfindRegisterQuotaOperationCompleted(object arg) {
            
if ((this.findRegisterQuotaCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs 
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                
this.findRegisterQuotaCompleted(thisnew findRegisterQuotaCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        
/// <remarks/>
        public new void CancelAsync(object userState) {
            
base.CancelAsync(userState);
        }
        
        
private bool IsLocalFileSystemWebService(string url) {
            
if (((url == null
                        
|| (url == string.Empty))) {
                
return false;
            }
            System.Uri wsUri 
= new System.Uri(url);
            
if (((wsUri.Port >= 1024
                        
&& (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
                
return true;
            }
            
return false;
        }
    }
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    
public delegate void registerCompletedEventHandler(object sender, registerCompletedEventArgs e);
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    
public partial class registerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        
private object[] results;
        
        
internal registerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                
base(exception, cancelled, userState) {
            
this.results = results;
        }
        
        
/// <remarks/>
        public string[] Result {
            
get {
                
this.RaiseExceptionIfNecessary();
                
return ((string[])(this.results[0]));
            }
        }
    }
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    
public delegate void findRegisterQuotaCompletedEventHandler(object sender, findRegisterQuotaCompletedEventArgs e);
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    
public partial class findRegisterQuotaCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        
private object[] results;
        
        
internal findRegisterQuotaCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                
base(exception, cancelled, userState) {
            
this.results = results;
        }
        
        
/// <remarks/>
        public string[] Result {
            
get {
                
this.RaiseExceptionIfNecessary();
                
return ((string[])(this.results[0]));
            }
        }
    }
}

#pragma warning restore 1591

   (2)调用对方服务修改后的CS文件 

代码
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行库版本:2.0.50727.3603
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

// 
// 此源代码是由 Microsoft.VSDesigner 2.0.50727.3603 版自动生成。
// 
#pragma warning disable 1591

namespace WebApplication2.WebReference {
    
using System.Diagnostics;
    
using System.Web.Services;
    
using System.ComponentModel;
    
using System.Web.Services.Protocols;
    
using System;
    
using System.Xml.Serialization;
    
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    [System.Web.Services.WebServiceBindingAttribute(Name
="RegisterServiceSoapBinding", Namespace="http://register.webservice.hnisi.com.cn")]
    
public partial class RegisterService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        
private System.Threading.SendOrPostCallback registerOperationCompleted;
        
        
private System.Threading.SendOrPostCallback findRegisterQuotaOperationCompleted;
        
        
private bool useDefaultCredentialsSetExplicitly;
        
        
/// <remarks/>
        public RegisterService() {
            
this.Url = global::WebApplication2.Properties.Settings.Default.WebApplication2_WebReference_RegisterService;
            
if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                
this.UseDefaultCredentials = true;
                
this.useDefaultCredentialsSetExplicitly = false;
            }
            
else {
                
this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        
public new string Url {
            
get {
                
return base.Url;
            }
            
set {
                
if ((((this.IsLocalFileSystemWebService(base.Url) == true
                            
&& (this.useDefaultCredentialsSetExplicitly == false)) 
                            
&& (this.IsLocalFileSystemWebService(value) == false))) {
                    
base.UseDefaultCredentials = false;
                }
                
base.Url = value;
            }
        }
        
        
public new bool UseDefaultCredentials {
            
get {
                
return base.UseDefaultCredentials;
            }
            
set {
                
base.UseDefaultCredentials = value;
                
this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        
/// <remarks/>
        public event registerCompletedEventHandler registerCompleted;
        
        
/// <remarks/>
        public event findRegisterQuotaCompletedEventHandler findRegisterQuotaCompleted;
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("RegisterReturn")]
        
public string[] register(string userID, string password, string[] citizenInfos) {
            
object[] results = this.Invoke("register"new object[] {
                        userID,
                        password,
                        citizenInfos});
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        public void registerAsync(string userID, string password, string[] citizenInfos) {
            
this.registerAsync(userID, password, citizenInfos, null);
        }
        
        
/// <remarks/>
        public void registerAsync(string userID, string password, string[] citizenInfos, object userState) {
            
if ((this.registerOperationCompleted == null)) {
                
this.registerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnregisterOperationCompleted);
            }
            
this.InvokeAsync("register"new object[] {
                        userID,
                        password,
                        citizenInfos}, 
this.registerOperationCompleted, userState);
        }
        
        
private void OnregisterOperationCompleted(object arg) {
            
if ((this.registerCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs 
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                
this.registerCompleted(thisnew registerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("FindRegisterQuotaReturn")]
        
public string[][] findRegisterQuota(string userID, string password, string annual, string departmentCode) {
            
object[] results = this.Invoke("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode});
            
return ((string[][])(results[0]));
        }
        
        
/// <remarks/>
        public void findRegisterQuotaAsync(string userID, string password, string annual, string departmentCode) {
            
this.findRegisterQuotaAsync(userID, password, annual, departmentCode, null);
        }
        
        
/// <remarks/>
        public void findRegisterQuotaAsync(string userID, string password, string annual, string departmentCode, object userState) {
            
if ((this.findRegisterQuotaOperationCompleted == null)) {
                
this.findRegisterQuotaOperationCompleted = new System.Threading.SendOrPostCallback(this.OnfindRegisterQuotaOperationCompleted);
            }
            
this.InvokeAsync("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode}, 
this.findRegisterQuotaOperationCompleted, userState);
        }
        
        
private void OnfindRegisterQuotaOperationCompleted(object arg) {
            
if ((this.findRegisterQuotaCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs 
= ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                
this.findRegisterQuotaCompleted(thisnew findRegisterQuotaCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        
/// <remarks/>
        public new void CancelAsync(object userState) {
            
base.CancelAsync(userState);
        }
        
        
private bool IsLocalFileSystemWebService(string url) {
            
if (((url == null
                        
|| (url == string.Empty))) {
                
return false;
            }
            System.Uri wsUri 
= new System.Uri(url);
            
if (((wsUri.Port >= 1024
                        
&& (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
                
return true;
            }
            
return false;
        }
    }
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    
public delegate void registerCompletedEventHandler(object sender, registerCompletedEventArgs e);
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    
public partial class registerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        
private object[] results;
        
        
internal registerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                
base(exception, cancelled, userState) {
            
this.results = results;
        }
        
        
/// <remarks/>
        public string[] Result {
            
get {
                
this.RaiseExceptionIfNecessary();
                
return ((string[])(this.results[0]));
            }
        }
    }
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    
public delegate void findRegisterQuotaCompletedEventHandler(object sender, findRegisterQuotaCompletedEventArgs e);
    
    
/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services""2.0.50727.3053")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute(
"code")]
    
public partial class findRegisterQuotaCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        
private object[] results;
        
        
internal findRegisterQuotaCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                
base(exception, cancelled, userState) {
            
this.results = results;
        }
        
        
/// <remarks/>
        public string[] Result {
            
get {
                
this.RaiseExceptionIfNecessary();
                
return ((string[])(this.results[0]));
            }
        }
    }
}

#pragma warning restore 1591

  3)调用对方接口返回的数据

            WebApplication2.WebReference.RegisterService rs = new WebApplication2.WebReference.RegisterService();

            string[][] s = rs.findRegisterQuota("test1", "2222", "2010", "S44010300");

            Response.Write("<table border=\"1\">");

            for (int i = 0; i < s.Length; i++)

            {

                Response.Write("<tr>");

                string[] a = s[i];

                for (int j = 0; j < a.Length; j++)

                {

                    Response.Write("<td>" + Convert.ToString(a[j]) + "&nbsp;</td>");

                }

                Response.Write("</tr>");

            }

            Response.Write("</table>");

  2.net3.0环境

  (1)调用对方服务生成的原始CS文件

代码
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行库版本:2.0.50727.3603
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

namespace WebApplication1.ServiceReference1 {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel""3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace
="http://register.webservice.hnisi.com.cn", ConfigurationName="ServiceReference1.RegisterService")]
    
public interface RegisterService {
        
        [System.ServiceModel.OperationContractAttribute(Action
="", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(Style
=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
        [
return: System.ServiceModel.MessageParameterAttribute(Name="RegisterReturn")]
        
string[] register(string userID, string password, string[] citizenInfos);
        
        [System.ServiceModel.OperationContractAttribute(Action
="", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(Style
=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
        [
return: System.ServiceModel.MessageParameterAttribute(Name="FindRegisterQuotaReturn")]
        
string[] findRegisterQuota(string userID, string password, string annual, string departmentCode);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel""3.0.0.0")]
    
public interface RegisterServiceChannel : WebApplication1.ServiceReference1.RegisterService, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel""3.0.0.0")]
    
public partial class RegisterServiceClient : System.ServiceModel.ClientBase<WebApplication1.ServiceReference1.RegisterService>, WebApplication1.ServiceReference1.RegisterService {
        
        
public RegisterServiceClient() {
        }
        
        
public RegisterServiceClient(string endpointConfigurationName) : 
                
base(endpointConfigurationName) {
        }
        
        
public RegisterServiceClient(string endpointConfigurationName, string remoteAddress) : 
                
base(endpointConfigurationName, remoteAddress) {
        }
        
        
public RegisterServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                
base(endpointConfigurationName, remoteAddress) {
        }
        
        
public RegisterServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                
base(binding, remoteAddress) {
        }
        
        
public string[] register(string userID, string password, string[] citizenInfos) {
            
return base.Channel.register(userID, password, citizenInfos);
        }
        
        
public string[] findRegisterQuota(string userID, string password, string annual, string departmentCode) {
            
return base.Channel.findRegisterQuota(userID, password, annual, departmentCode);
        }
    }
}

         (2)调用对方服务修改后的CS文件

代码
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行库版本:2.0.50727.3603
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

namespace WebApplication1.ServiceReference1 {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel""3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace
="http://register.webservice.hnisi.com.cn", ConfigurationName="ServiceReference1.RegisterService")]
    
public interface RegisterService {
        
        [System.ServiceModel.OperationContractAttribute(Action
="", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(Style
=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
        [
return: System.ServiceModel.MessageParameterAttribute(Name="RegisterReturn")]
        
string[] register(string userID, string password, string[] citizenInfos);
        
        [System.ServiceModel.OperationContractAttribute(Action
="", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(Style
=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
        [
return: System.ServiceModel.MessageParameterAttribute(Name="FindRegisterQuotaReturn")]
        
string[][] findRegisterQuota(string userID, string password, string annual, string departmentCode);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel""3.0.0.0")]
    
public interface RegisterServiceChannel : WebApplication1.ServiceReference1.RegisterService, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.ServiceModel""3.0.0.0")]
    
public partial class RegisterServiceClient : System.ServiceModel.ClientBase<WebApplication1.ServiceReference1.RegisterService>, WebApplication1.ServiceReference1.RegisterService {
        
        
public RegisterServiceClient() {
        }
        
        
public RegisterServiceClient(string endpointConfigurationName) : 
                
base(endpointConfigurationName) {
        }
        
        
public RegisterServiceClient(string endpointConfigurationName, string remoteAddress) : 
                
base(endpointConfigurationName, remoteAddress) {
        }
        
        
public RegisterServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                
base(endpointConfigurationName, remoteAddress) {
        }
        
        
public RegisterServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                
base(binding, remoteAddress) {
        }
        
        
public string[] register(string userID, string password, string[] citizenInfos) {
            
return base.Channel.register(userID, password, citizenInfos);
        }
        
        
public string[][] findRegisterQuota(string userID, string password, string annual, string departmentCode) {
            
return base.Channel.findRegisterQuota(userID, password, annual, departmentCode);
        }
    }
}

  3)调用对方接口返回的数据
            WebApplication1.ServiceReference1.RegisterServiceClient rs = new WebApplication1.ServiceReference1.RegisterServiceClient();
            string[][] s = rs.findRegisterQuota("test1", "2222", "2010", "S44010300");
            Response.Write("<table border=\"1\">");
            for (int i = 0; i < s.Length; i++)
            {
                Response.Write("<tr>");
                string[] a = s[i];
                for (int j = 0; j < a.Length; j++)
                {
                    Response.Write("<td>" + Convert.ToString(a[j]) + "&nbsp;</td>");
                }
                Response.Write("</tr>");
            }
            Response.Write("</table>");
        }

 

  3.net1.1环境

  (1)调用对方服务生成的原始CS文件

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

// 
// 此源代码是由 Microsoft.VSDesigner 1.1.4322.2463 版自动生成。
// 
namespace WebApplication1.WebReference {
    
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
="RegisterServiceSoapBinding", Namespace="http://register.webservice.hnisi.com.cn")]
    
public class RegisterService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        
/// <remarks/>
        public RegisterService() {
            
this.Url = "http://172.16.70.40:7001/rhsh/services/RegisterService";
        }
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("RegisterReturn")]
        
public string[] register(string userID, string password, string[] citizenInfos) {
            
object[] results = this.Invoke("register"new object[] {
                        userID,
                        password,
                        citizenInfos});
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        public System.IAsyncResult Beginregister(string userID, string password, string[] citizenInfos, System.AsyncCallback callback, object asyncState) {
            
return this.BeginInvoke("register"new object[] {
                        userID,
                        password,
                        citizenInfos}, callback, asyncState);
        }
        
        
/// <remarks/>
        public string[] Endregister(System.IAsyncResult asyncResult) {
            
object[] results = this.EndInvoke(asyncResult);
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("FindRegisterQuotaReturn")]
        
public string[] findRegisterQuota(string userID, string password, string annual, string departmentCode) {
            
object[] results = this.Invoke("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode});
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        public System.IAsyncResult BeginfindRegisterQuota(string userID, string password, string annual, string departmentCode, System.AsyncCallback callback, object asyncState) {
            
return this.BeginInvoke("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode}, callback, asyncState);
        }
        
        
/// <remarks/>
        public string[] EndfindRegisterQuota(System.IAsyncResult asyncResult) {
            
object[] results = this.EndInvoke(asyncResult);
            
return ((string[])(results[0]));
        }
    }
}

         (2)调用对方服务修改后的CS文件

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

// 
// 此源代码是由 Microsoft.VSDesigner 1.1.4322.2463 版自动生成。
// 
namespace WebApplication1.WebReference {
    
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
="RegisterServiceSoapBinding", Namespace="http://register.webservice.hnisi.com.cn")]
    
public class RegisterService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        
/// <remarks/>
        public RegisterService() {
            
this.Url = "http://172.16.70.40:7001/rhsh/services/RegisterService";
        }
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("RegisterReturn")]
        
public string[] register(string userID, string password, string[] citizenInfos) {
            
object[] results = this.Invoke("register"new object[] {
                        userID,
                        password,
                        citizenInfos});
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        public System.IAsyncResult Beginregister(string userID, string password, string[] citizenInfos, System.AsyncCallback callback, object asyncState) {
            
return this.BeginInvoke("register"new object[] {
                        userID,
                        password,
                        citizenInfos}, callback, asyncState);
        }
        
        
/// <remarks/>
        public string[] Endregister(System.IAsyncResult asyncResult) {
            
object[] results = this.EndInvoke(asyncResult);
            
return ((string[])(results[0]));
        }
        
        
/// <remarks/>
        [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://register.webservice.hnisi.com.cn", ResponseNamespace="http://register.webservice.hnisi.com.cn")]
        [
return: System.Xml.Serialization.SoapElementAttribute("FindRegisterQuotaReturn")]
        
public string[][] findRegisterQuota(string userID, string password, string annual, string departmentCode) {
            
object[] results = this.Invoke("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode});
            
return ((string[][])(results[0]));
        }
        
        
/// <remarks/>
        public System.IAsyncResult BeginfindRegisterQuota(string userID, string password, string annual, string departmentCode, System.AsyncCallback callback, object asyncState) {
            
return this.BeginInvoke("findRegisterQuota"new object[] {
                        userID,
                        password,
                        annual,
                        departmentCode}, callback, asyncState);
        }
        
        
/// <remarks/>
        public string[] EndfindRegisterQuota(System.IAsyncResult asyncResult) {
            
object[] results = this.EndInvoke(asyncResult);
            
return ((string[])(results[0]));
        }
    }
}

     (3)调用对方接口返回数据时提示的错误

              WebApplication1.WebReference.RegisterService rs = new WebApplication1.WebReference.RegisterService();

              string[][] s = rs.findRegisterQuota("test1", "2222", "2010", "S44010300");

              Response.Write("<table border=\"1\">");

              for (int i = 0; i < s.Length; i++)

              {

                   Response.Write("<tr>");

                   string[] a = s[i];

                   for (int j = 0; j < a.Length; j++)

                   {

                       Response.Write("<td>" + Convert.ToString(a[j]) + "&nbsp;</td>");

                   }

                   Response.Write("</tr>");

              }

              Response.Write("</table>");

  二、问题解决方法
  此问题的解决,得首先感谢Galactica的热心帮助,具体实现代码如下:

代码
            //string uri = "http://172.16.70.40:7001/rhsh/services/RegisterService";  //修改前,原因:此地址无法访问
            string uri = "http://172.16.70.40:7001/rhsh/services/RegisterService?wsdl"//修改后 
            HttpWebRequest hwRequest = (HttpWebRequest)WebRequest.Create(uri);           
            
// 下面这些的参数,以及不包括在这里的参数,也就是           
            
// HTTP Headers 中包含的参数的具体值需要根据对方           
            
// 服务器的设置而定。           
            hwRequest.Method = "POST";          
            hwRequest.ContentType 
= "text/xml;charset=UTF-8";     
            hwRequest.Headers.Add(
"SOAPAction""*");  // 不知道,假装不知道。       
            hwRequest.UserAgent = "Jakarta Commons-HttpClient/3.1";           
            
//hwRequest.Host = "register.webservice.hnisi.com.cn";   //没有Host的属性     
            hwRequest.Timeout = 1000 * 60 * 3;         
            hwRequest.KeepAlive 
= false;           
            
// 对方是 Apache            
            hwRequest.ServicePoint.Expect100Continue = false;      
            
// 从 FindRegisterRequest.xml 读取请求数据。         
            
// 因为我们需要修改请求中的一些参数,也就是输入参数,   
            
// 因此,我们使用 XmlDocument 来简化操作。           
            XmlDocument xmlDoc = new XmlDocument();           
            xmlDoc.Load(
"RegisterService.xml");  //报错,提示找不到文件RegisterService.xml       
            XmlNode userIDNode = xmlDoc.GetElementsByTagName("userID")[0];       
            userIDNode.InnerText 
= "test1";            
            XmlNode pwdNode 
= xmlDoc.GetElementsByTagName("password")[0];         
            pwdNode.InnerText 
= "2222";           
            XmlNode annualNode 
= xmlDoc.GetElementsByTagName("annual")[0];         
            annualNode.InnerText 
= "2010";           
            XmlNode depCodeNode 
= xmlDoc.GetElementsByTagName("departmentCode")[0];          
            depCodeNode.InnerText 
= "S44010300";           
            
byte[] sendBuffer = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);           
            hwRequest.ContentLength 
= sendBuffer.Length;            
            
// 写 POST 数据            
            using (Stream reqStream = hwRequest.GetRequestStream())               
                reqStream.Write(sendBuffer, 
0, sendBuffer.Length);           
            
// 接受响应            
            HttpWebResponse hwResponse = (HttpWebResponse)hwRequest.GetResponse();            
            
try            
            {                
                
using (Stream resStream = hwResponse.GetResponseStream())                
                {                   
                    
using (StreamReader sr = new StreamReader(resStream))                   
                    {                        
                        
// 如果上面都没有出错的话,这里就读到结果了,                        
                        
// 我只是简单的转换成 string,就是方便查看,                       
                        
// 如果确切的知道响应的 SOAP 格式,就可以读取出来。                       
                        string xmlText = sr.ReadToEnd();    
                        XmlDocument xdDoc 
= new XmlDocument();           
                        xdDoc.LoadXml(xmlText);            
                        XmlNode quotaResponse 
= xdDoc.DocumentElement.FirstChild.FirstChild;            
                        
if (!quotaResponse.HasChildNodes || quotaResponse == null)                
                            
return;            
                        XmlNode quotaReturn 
= quotaResponse.FirstChild;            
                        
if (!quotaReturn.HasChildNodes || quotaReturn == null)                
                            
return;                                    
                        
string[][] array = new string[quotaReturn.ChildNodes.Count][];            
                        
for (int i = 0, j = array.Length; i < j; i++)            
                        {                
                            XmlNodeList nodes 
= quotaReturn.ChildNodes[i].ChildNodes;                
                            array[i] 
= new string[nodes.Count];                
                            
for (int m = 0, n = array[i].Length; m < n; m++)                
                            {                    
                                array[i][m] 
= nodes[m].InnerText;                
                            }            
                        }

                        Response.Write(
"<table border=\"1\">");
                        
for (int i = 0; i < array.Length; i++)
                        {
                            Response.Write(
"<tr>");
                            
string[] a = array[i];
                            
for (int j = 0; j < a.Length; j++)
                            {
                                Response.Write(
"<td>" + Convert.ToString(a[j]) + "&nbsp;</td>");
                            }
                            Response.Write(
"</tr>");
                        }
                        Response.Write(
"</table>");
                    }               
                }           
            }            
            
finally            
            {                
                hwResponse.Close();           
            }

  

RegisterService.xml
<?xml version="1.0" encoding="utf-8" ?> 
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:reg="http://register.webservice.hnisi.com.cn">  
<soapenv:Header/> 
<soapenv:Body>    
<reg:findRegisterQuota soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">      
<userID xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</userID>      
<password xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</password>      
<annual xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</annual>      
<departmentCode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</departmentCode>    
</reg:findRegisterQuota>  
</soapenv:Body>
</soapenv:Envelope>

 

  得到的xmlText值为一个XML文档,具体信息如下:

代码
<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
    
<soapenv:Body>
        
<ns1:findRegisterQuotaResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"http://register.webservice.hnisi.com.cn\">
            
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[][3]\" xsi:type=\"soapenc:Array\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">
                
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[12]\" xsi:type=\"soapenc:Array\">
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ID</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">YEAR</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">KIND</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">TOTAL</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">BEGINNUMBER</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ENDNUMBER</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">CURRENTPOINTER</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">BEGINTIME</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ENDTIME</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">USINGDEPT</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">YRDW</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ZY</FindRegisterQuotaReturn>
                
</FindRegisterQuotaReturn>
                
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[12]\" xsi:type=\"soapenc:Array\">
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">RHSH440120100512006766</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">2010</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">50000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">1</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">50000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">1</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20100512000000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20110101000000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">S44010300</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
                
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
                
</FindRegisterQuotaReturn>
                
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[12]\" xsi:type=\"soapenc:Array\">
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">RHSH440120100512006763</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">2010</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">10</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">50000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20001</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">70000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20002</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20100512000000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20110101000000</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">S44010300</FindRegisterQuotaReturn>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
                    
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
                
</FindRegisterQuotaReturn>
            
</FindRegisterQuotaReturn>
        
</ns1:findRegisterQuotaResponse>
    
</soapenv:Body>
</soapenv:Envelope>"

 

  读取XML中的数据,显示如下图: