无法使用故障合同实例化客户端WCF

时间:2013-05-24 15:03:53

标签: c# .net wcf

当出现故障合同时,我在为WCF服务创建客户端时遇到问题。

当我把错误契约,客户端无法实例化时,它只能看到WPCILServiceException对象和WPCILEndResponse对象。

下面是服务的工作代码,没有错误合同:

namespace WcfS001
{ 
[ServiceContract]
    public interface IS001
    {


        [OperationContract]  
        WPCILEndResponse GetMasterListDebug(string xml);

        [OperationContract]
        WPCILEndResponse GetMasterListWpc(S001_WPC_Input input);
    }
}

当我使用Windows Form创建客户端时,我创建了一个调用此服务的按钮,如下所示:

    private void button1_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(textBoxInput.Text))
        {
            S001Service.S001Client clientConnection = new S001Service.S001Client();
            try
            {
                S001Service.WPCILEndResponse response = clientConnection.GetMasterListDebug(textBoxInput.Text);
                textBoxCorrId.Text = response._correlationId;
                textBoxService.Text = response._service;

            }
            catch (Exception ex)
            {
                textBoxEx.Text = ex.Message;

            }
        }
        else 
        { 
            MessageBox.Show("Input textbox is empty!");
        }

    }

我可以毫无问题地看到“S001Service.S001Client”。

但是,当我添加如下的故障合同时,“S001Service.S001Client”不再存在,即使在对象浏览器中也看不到它。我只能看到异常对象类型!

namespace WcfS001
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IS001" in both code and config file together.

    [ServiceContract]
    public interface IS001
    {


        [OperationContract]
        [FaultContract(typeof(WPCILServiceException))]   
        WPCILEndResponse GetMasterListDebug(string xml);

        [OperationContract]
        [FaultContract(typeof(WPCILServiceException))]   
        WPCILEndResponse GetMasterListWpc(S001_WPC_Input input);

    }
}

所以下面的代码不再起作用了

   private void button1_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(textBoxInput.Text))
        {
            **//S001Client doesn't exists anymore - why???
            S001Service.S001Client clientConnection = new S001Service.S001Client();**
            try
            {
                S001Service.WPCILEndResponse response = clientConnection.GetMasterListDebug(textBoxInput.Text);
                textBoxCorrId.Text = response._correlationId;
                textBoxService.Text = response._service;

            }
            catch (Exception ex)
            {
                textBoxEx.Text = ex.Message;

            }
        }
        else 
        { 
            MessageBox.Show("Input textbox is empty!");
        }

    }

好像我的客户端无法读取正确的WSDL(附在下面):

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="S001" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/CustomILException"/>
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/ModelsInputOutput.WPCILEndResponse"/>
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd4" namespace="http://schemas.datacontract.org/2004/07/System"/>
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd5" namespace="http://schemas.datacontract.org/2004/07/S001InputWpc"/>
<xsd:import schemaLocation="http://localhost:5006/S001.svc?xsd=xsd6" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IS001_GetMasterListDebug_InputMessage">
<wsdl:part name="parameters" element="tns:GetMasterListDebug"/>
</wsdl:message>
<wsdl:message name="IS001_GetMasterListDebug_OutputMessage">
<wsdl:part name="parameters" element="tns:GetMasterListDebugResponse"/>
</wsdl:message>
<wsdl:message name="IS001_GetMasterListDebug_WPCILServiceExceptionFault_FaultMessage">
<wsdl:part xmlns:q1="http://schemas.datacontract.org/2004/07/CustomILException" name="detail" element="q1:WPCILServiceException"/>
</wsdl:message>
<wsdl:message name="IS001_GetMasterListWpc_InputMessage">
<wsdl:part name="parameters" element="tns:GetMasterListWpc"/>
</wsdl:message>
<wsdl:message name="IS001_GetMasterListWpc_OutputMessage">
<wsdl:part name="parameters" element="tns:GetMasterListWpcResponse"/>
</wsdl:message>
<wsdl:message name="IS001_GetMasterListWpc_WPCILServiceExceptionFault_FaultMessage">
<wsdl:part xmlns:q2="http://schemas.datacontract.org/2004/07/CustomILException" name="detail" element="q2:WPCILServiceException"/>
</wsdl:message>
<wsdl:portType name="IS001">
<wsdl:operation name="GetMasterListDebug">
<wsdl:input wsaw:Action="http://tempuri.org/IS001/GetMasterListDebug" message="tns:IS001_GetMasterListDebug_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IS001/GetMasterListDebugResponse" message="tns:IS001_GetMasterListDebug_OutputMessage"/>
<wsdl:fault wsaw:Action="http://tempuri.org/IS001/GetMasterListDebugWPCILServiceExceptionFault" name="WPCILServiceExceptionFault" message="tns:IS001_GetMasterListDebug_WPCILServiceExceptionFault_FaultMessage"/>
</wsdl:operation>
<wsdl:operation name="GetMasterListWpc">
<wsdl:input wsaw:Action="http://tempuri.org/IS001/GetMasterListWpc" message="tns:IS001_GetMasterListWpc_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IS001/GetMasterListWpcResponse" message="tns:IS001_GetMasterListWpc_OutputMessage"/>
<wsdl:fault wsaw:Action="http://tempuri.org/IS001/GetMasterListWpcWPCILServiceExceptionFault" name="WPCILServiceExceptionFault" message="tns:IS001_GetMasterListWpc_WPCILServiceExceptionFault_FaultMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IS001" type="tns:IS001">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetMasterListDebug">
<soap:operation soapAction="http://tempuri.org/IS001/GetMasterListDebug" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WPCILServiceExceptionFault">
<soap:fault name="WPCILServiceExceptionFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="GetMasterListWpc">
<soap:operation soapAction="http://tempuri.org/IS001/GetMasterListWpc" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WPCILServiceExceptionFault">
<soap:fault name="WPCILServiceExceptionFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="S001">
<wsdl:port name="BasicHttpBinding_IS001" binding="tns:BasicHttpBinding_IS001">
<soap:address location="http://localhost:5006/S001.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

我从来没有使用过错合同......我错过了什么吗?

谢谢

0 个答案:

没有答案
相关问题