Call Web Service方法在VS 2008中返回null

问题描述 投票:-1回答:1

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

显然,这是一个众所周知的问题,并且有很好的解决方案。抱歉,这次我找不到解决方法!

[还有其他一些情况,例如我的(like this),但它对我不起作用。

这是WSDL:

<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://XXXXXX:9089/WSFDAxis/services/SOAPMessageDispatcher" xmlns:intf="http://XXXXXX:9089/WSFDAxis/services/SOAPMessageDispatcher" xmlns:tns1="http://testsite.com" 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://XXXXX:9089/WSFDAxis/services/SOAPMessageDispatcher">
<wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://testsite.com">
        <element name="process" type="xsd:anyType"/>
    </schema>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://XXXXX: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://XXXXX:9089/WSFDAxis/services/SOAPMessageDispatcher"/>
    </wsdl:port>
</wsdl:service>

这是VS 2008通过bwwn创建的自动定义:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://XXXXX: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://testsite.com", 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://XXXXXX: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;
    }
}

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

    /// <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://XXXXX: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://XXXXX:9089/WSFDAxis/services/SOAPMessageDispatcher")]
    public object process([System.Xml.Serialization.XmlElementAttribute("process", Namespace="http://testsite.com")] 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]));
        }
    }
}

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

感谢大家。

c# vb.net visual-studio-2008 axis
1个回答
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 &= "<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
© www.soinside.com 2019 - 2024. All rights reserved.