Consuming non-wcf SOAP fault from WCF client (soap fault defined)

回眸只為那壹抹淺笑 提交于 2019-12-05 10:28:14

Have your tried doing something like the code shown below, you need to catch the specific soap fault contract that has the information you are looking for. The information in this MSDN article should help.

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();
}

I think Sixto Saez is right. You can see the BtsSoapException instance inside of the FaultException.

Definition:

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

Response:

<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>

if you do

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

you must see "java.lang.Exception: No user profile defined in the database for fakeuser" in the output window when you are debugging.

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