Search code examples
c#phpsoapweb-servicessoapfault

Check in C# whether php soap returned soapFault


I have problem with checking SoapFault response from writen in PHP Soap webservice. Responce looks like this (default "throw new SoapFault("SOAP:CLIENT", "Bad login");"

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
    <SOAP-ENV:Fault>
        <faultcode>SOAP:CLIENT</faultcode>
        <faultstring>Bad login</faultstring>
    </SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And C# code looks like this:

try
{
   //creating new webservice, filling headers and alling something
   webservice = new...
   items = webservice.getSth();
}
catch ( Exception ex )
{
   MessageBox.Show(ex.Message); -> "Namespace prefix 'SOAP' not defined"
}

When login/pass/apikey etc is OK than i get what i need, but when sth is wrong than i cant display proper information.

How to check if SOAP returned fault? I googled for the problem, but couldnt find valuable information.

Unfortunetly i cant change webservice.

Thanks for any help.


Solution

  • catch (SoapException ex)
    {
        Console.WriteLine(ex.Detail.OuterXml);
    }