Consumption of non-wcf SOAP error from WCF client (soap error detected)

I have a non-wcf server that I call from the WCF client, and I need to access the registered soap error if the server throws it (it contains the feedback that I need for the user). I used the example from How to get SOAP 1.1 failure information from a WCF client (without a failure contract) , but it’s a pain if I have a failure contract defined in wsdl, at least according to the SOAP specification, and the error contains error code and error string.

<wsdl:types>
    <schema elementFormDefault="qualified" targetNamespace="http://www.cisco.com/BTS10200/i01" xmlns="http://www.w3.org/2001/XMLSchema">
        ...
        <complexType name="BtsSoapException">
            <sequence>
                <element name="error_code" type="xsd:int"/>
                <element name="error_string" nillable="true" type="xsd:string"/>
            </sequence>
        </complexType>
        <element name="fault" type="impl:BtsSoapException"/>
...

<wsdl:message name="BtsSoapException">
    <wsdl:part element="impl:fault" name="fault"/>
</wsdl:message>
...

<wsdl:portType name="Bts10200Operations">
    <wsdl:operation name="login">
        <wsdl:input message="impl:loginRequest" name="loginRequest"/>
        <wsdl:output message="impl:loginResponse" name="loginResponse"/>
        <wsdl:fault message="impl:BtsSoapException" name="BtsSoapException"/>
    </wsdl:operation>
...

Service import recognizes all this correctly and generates the correct code constructs:

[System.Runtime.Serialization.DataContractAttribute(Name="BtsSoapException", Namespace="http://www.cisco.com/BTS10200/i01")]
[System.SerializableAttribute()]
public partial class BtsSoapException : object ...

....

[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.cisco.com/BTS10200/i01", ConfigurationName="CiscoBTSService.Bts10200Operations")]
public interface Bts10200Operations {
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.FaultContractAttribute(typeof(TestCiscoBTS.CiscoBTSService.BtsSoapException), Action="", Name="fault")]
    TestCiscoBTS.CiscoBTSService.loginResponse login(TestCiscoBTS.CiscoBTSService.loginRequest request);
...

When I call login()with an invalid account, I get the correct answer on wsdl:

<?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>
        <soapenv:Fault>
            <faultcode>soapenv:Server.generalException</faultcode>
            <faultstring></faultstring>
            <detail>
                <ns1:fault xmlns:ns1="http://www.cisco.com/BTS10200/i01">
                    <error_code>401</error_code>
                    <error_string xsi:type="xsd:string">java.lang.Exception: No user profile defined in the database for fakeuser</error_string>
                </ns1:fault>
                <ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/">com.sswitch.oam.soap.intf.BtsSoapException</ns2:exceptionName>
                <ns3:stackTrace xmlns:ns3="http://xml.apache.org/axis/">
    at com.sswitch.oam.soap.impl.UserAuth.validateUser(UserAuth.java:63)
    ...

FaultExcpetion , (Message= ""), , BtsSoapException. ( wcf , ). ? WCF FaultException<BtsSoapException>?

+5
2

- , , , , . MSDN .

var proxy = new WhatEverYourServiceProxyClassIsNamed();
try
{
    //your call logic here

    proxy.Close();
}
catch (FaultException<BtsSoapException> bse)
{
    //Get the info you're looking for in the strongly typed soap fault:

    proxy.Abort();
}
catch (FaultException fe)
{
    //Do something appropriate for a non-typed soap fault

    proxy.Abort();
}
finally
{
    if ((ICommunicationObject)proxy).State != CommunicationState.Closed)
        proxy.Abort();
}
+2

, . BtsSoapException FaultException.

:

<complexType name="BtsSoapException">
    <sequence>
        <element name="error_code" type="xsd:int"/>
        <element name="error_string" nillable="true" type="xsd:string"/>
    </sequence>
</complexType>

:

<detail>
    <ns1:fault xmlns:ns1="http://www.cisco.com/BTS10200/i01">
        <error_code>401</error_code>
        <error_string xsi:type="xsd:string">java.lang.Exception: No user profile defined in the database for fakeuser</error_string>

catch (FaultException<BtsSoapException> bse)
{
    console.write(bse.Detail.error_string)
}

"java.lang.Exception: , fakeuser" .

0

All Articles