Call web service method returns null in VS 2008

江枫思渺然 提交于 2019-12-08 15:18:53

问题


My situation: I have a Winform App (.NET 2008) and i have to consume a web service (Java Axis). I´m using SoapUI to test the web service and it works fine. However when I use it via Service Reference in my VS 2008 it returns null.

Apparently, it seems a well known problem and it has a good solution. Sorry, I cant find the solution this time!!

There is some other cases like mine (like this), but it is not working for me.

This is the WSDL:

<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher" xmlns:intf="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher" xmlns:tns1="http://services.web.wsfd.bancorio.com.ar" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher">
<wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://services.web.wsfd.bancorio.com.ar">
        <element name="process" type="xsd:anyType"/>
    </schema>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher">
        <element name="processReturn" type="xsd:anyType"/>
    </schema>
</wsdl:types>
<wsdl:message name="processRequest">
    <wsdl:part element="tns1:process" name="part"/>
</wsdl:message>
<wsdl:message name="processResponse">
    <wsdl:part element="impl:processReturn" name="processReturn"/>
</wsdl:message>
<wsdl:portType name="SOAPService">
    <wsdl:operation name="process">
        <wsdl:input message="impl:processRequest" name="processRequest"/>
        <wsdl:output message="impl:processResponse" name="processResponse"/>
    </wsdl:operation>
</wsdl:portType>
    <wsdl:binding name="SOAPMessageDispatcherSoapBinding" type="impl:SOAPService">
    <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="process">
        <wsdlsoap:operation soapAction=""/>
        <wsdl:input name="processRequest">
        <wsdlsoap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="processResponse">
        <wsdlsoap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="SOAPServiceService">
    <wsdl:port binding="impl:SOAPMessageDispatcherSoapBinding" name="SOAPMessageDispatcher">
        <wsdlsoap:address location="http://wds2.ar.bsch:9089/WSFDAxis/services/SOAPMessageDispatcher"/>
    </wsdl:port>
</wsdl:service>

This is the auto-definition VS 2008 has bwwn created:

    [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>, 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;
    }
}

Finally I changed from Service Reference to Web Reference. This is the definition created by VS 2008 for Web Reference:

    /// <remarks/>
[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;

    /// <remarks/>
    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;
        }
    }

    /// <remarks/>
    public event processCompletedEventHandler processCompleted;

    /// <remarks/>
    [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]));
    }

    /// <remarks/>
    public void processAsync(object process1) {
        this.processAsync(process1, null);
    }

    /// <remarks/>
    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));
        }
    }

    /// <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.5420")]
public delegate void processCompletedEventHandler(object sender, processCompletedEventArgs e);

/// <remarks/>
[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;
    }

    /// <remarks/>
    public object Result {
        get {
            this.RaiseExceptionIfNecessary();
            return ((object)(this.results[0]));
        }
    }
}

I was reading to many forums on this site, and more. But i cant find the solution.

Thanks to everyone.


回答1:


Actually I solved (temporary, like a caveman) doing a web request and reading a web response. Is it working? Yes, but I think that it's not a good way, not quality way.

I think It must be solved, somewhere, by somebody.

I did something like this:

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 &= "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ser=""http://services.web.wsfd.bancorio.com.ar"">"
    mensaje &= "    <soapenv:Header/>"
    mensaje &= "    <soapenv:Body>"
    mensaje &= "{0}"
    mensaje &= "    </soapenv:Body>"
    mensaje &= "</soapenv:Envelope>"

    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


来源:https://stackoverflow.com/questions/31075590/call-web-service-method-returns-null-in-vs-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!