调用Web服务方法在VS 2008中返回null

我的情况:我有一个Winform应用程序(.NET 2008),我必须使用Web服务(Java Axis)。 我使用SoapUI测试Web服务,它工作正常。 但是,当我在VS 2008中通过服务引用使用它时,它返回null。

显然,它似乎是一个众所周知的问题,它有一个很好的解决方案。 对不起,这次我找不到解决方案!

还有其他一些像我这样的情况( 像这样 ),但它对我不起作用。

这是WSDL:

                                      

这是自动定义VS 2008已创建:

  [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] [System.ServiceModel.ServiceContractAttribute(Namespace="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher", ConfigurationName="ServiceReference1.SOAPService")] public interface SOAPService { // CODEGEN: Se está generando un contrato de mensaje, ya que la operación process no es RPC ni está encapsulada en un documento. [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")] [System.ServiceModel.XmlSerializerFormatAttribute()] WindowsFormsApplication3.ServiceReference1.processResponse process(WindowsFormsApplication3.ServiceReference1.processRequest request); } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] public partial class processRequest { [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://services.web.wsfd.bancorio.com.ar", Order=0)] public object process; public processRequest() { } public processRequest(object process) { this.process = process; } } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] public partial class processResponse { [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher", Order=0)] public object processReturn; public processResponse() { } public processResponse(object processReturn) { this.processReturn = processReturn; } } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public interface SOAPServiceChannel : WindowsFormsApplication3.ServiceReference1.SOAPService, System.ServiceModel.IClientChannel { } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public partial class SOAPServiceClient : System.ServiceModel.ClientBase, WindowsFormsApplication3.ServiceReference1.SOAPService { public SOAPServiceClient() { } public SOAPServiceClient(string endpointConfigurationName) : base(endpointConfigurationName) { } public SOAPServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public SOAPServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public SOAPServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] WindowsFormsApplication3.ServiceReference1.processResponse WindowsFormsApplication3.ServiceReference1.SOAPService.process(WindowsFormsApplication3.ServiceReference1.processRequest request) { return base.Channel.process(request); } public object process(object process1) { WindowsFormsApplication3.ServiceReference1.processRequest inValue = new WindowsFormsApplication3.ServiceReference1.processRequest(); inValue.process = process1; WindowsFormsApplication3.ServiceReference1.processResponse retVal = ((WindowsFormsApplication3.ServiceReference1.SOAPService)(this)).process(inValue); return retVal.processReturn; } } 

最后,我从服务参考更改为Web参考。 这是VS 2008 for Web Reference创建的定义:

  ///  [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5420")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Web.Services.WebServiceBindingAttribute(Name="SOAPMessageDispatcherSoapBinding", Namespace="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher")] public partial class SOAPServiceService : System.Web.Services.Protocols.SoapHttpClientProtocol { private System.Threading.SendOrPostCallback processOperationCompleted; private bool useDefaultCredentialsSetExplicitly; ///  public SOAPServiceService() { this.Url = global::WindowsFormsApplication3.Properties.Settings.Default.WindowsFormsApplication3_ServicioDeFirma_SOAPServiceService; 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; } } ///  public event processCompletedEventHandler processCompleted; ///  [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)] [return: System.Xml.Serialization.XmlElementAttribute("processReturn", Namespace="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher")] public object process([System.Xml.Serialization.XmlElementAttribute("process", Namespace="http://services.web.wsfd.bancorio.com.ar")] object process1) { object[] results = this.Invoke("process", new object[] { process1}); return ((object)(results[0])); } ///  public void processAsync(object process1) { this.processAsync(process1, null); } ///  public void processAsync(object process1, object userState) { if ((this.processOperationCompleted == null)) { this.processOperationCompleted = new System.Threading.SendOrPostCallback(this.OnprocessOperationCompleted); } this.InvokeAsync("process", new object[] { process1}, this.processOperationCompleted, userState); } private void OnprocessOperationCompleted(object arg) { if ((this.processCompleted != null)) { System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); this.processCompleted(this, new processCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); } } ///  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; } } ///  [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5420")] public delegate void processCompletedEventHandler(object sender, processCompletedEventArgs e); ///  [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5420")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] public partial class processCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { private object[] results; internal processCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : base(exception, cancelled, userState) { this.results = results; } ///  public object Result { get { this.RaiseExceptionIfNecessary(); return ((object)(this.results[0])); } } } 

我正在阅读本网站上的许多论坛,等等。 但我找不到解决方案。

谢谢大家。

实际上我解决了(临时,像个穴居人)做网页请求和阅读网页回复。 它有效吗? 是的,但我认为这不是一个好方法,不是质量方式。

我认为它必须在某个地方由某人解决。

我做了这样的事情:

 Using cliente As New WebClient() cliente.Headers.Add("SOAPAction", """http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher""") cliente.Headers.Add("Content-Type", "text/xml; charset=utf-8") Dim mensaje As String = String.Empty mensaje &= "" mensaje &= " " mensaje &= " " mensaje &= "{0}" mensaje &= " " mensaje &= "" Dim data = Encoding.UTF8.GetBytes(mensaje) Dim result = cliente.UploadData("http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher", data) Dim xml = New XmlDocument() xml.LoadXml(result) Dim nodes = xml.GetElementsByTagName("codRet") Dim codRet = String.Empty For Each node As XmlNode In nodes codRet = node.InnerText Next Return CInt(codRet) = 0 End Using