Robert Wilczynski wrote:
Instead what I would do would be to create your own base proxy class MyHttpClientProtocol
deriving from SoapHttpClientProtocol and override the Invoke method:
protected override object[] Invoke(string methodName, object[] parameters)
{
try
{
base.Invoke(methodName, parameters);
} catch (SoapException ex)
{
throw GetCustomException(ex);
}
}
where GetCustomException would provide an instance of your own exception
based on the fault code and subcode. I believe you could point wsdl.exe to
this use this class as a base class for the proxy it generates. This probably
is, at least conceptually, the easiest approach.
Rob:
Thanks a lot for your advices. But I still have problem on this easiest
approach.
I created a custom exception class MyWizardException, and created my
own
base proxy class MyHttpClientProtocol derived from
SoapHttpClientProtocol and
override the Invoke method. But I got the following error:
'MyDOC1.MyWebReference.MyHttpClientProtocol.Invoke (string, object[])' :
cannot override inherited member
'System.Web.Services.Protocols.SoapHttpClientProto col.Invoke(string,
object[])' because it is not marked virtual, abstract, or override
Here's the SOAP response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode
xmlns:ns201420873="http://mywizard.wws"
xmlns="">ns201420873:MyWizardException</faultcode><faultstring
xmlns=""><![CDATA[wws.mywizard.MyWizardException: sequence number need
to be >0]]></faultstring><detail xmlns=""><MyWizardGException
xmlns="http://mywizard.wws"><info>info001</info><message>sequence
number need to be
>0</message><id>1</id></MyWizardGException></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
My objective is to extract the <info>, <message>, and <id> elements.
And then map those values to the custom exception class
MyWizardException
In visual studio autogenerated proxy file, I added and modified the
following:
public class MyWizardException : System.ApplicationException
{
public string info;
public string message;
public int id;
public MyWizardException(string aInfo, string aMessage, int aId)
{
info = aInfo;
message = aMessage;
id = aId;
}
}
public class MyHttpClientProtocol :
System.Web.Services.Protocols.SoapHttpClientProtoc ol
{
protected override object[] Invoke(string methodname, object[]
parameters)
{
try
{
base.Invoke(methodname, parameters);
}
catch(System.Web.Services.Protocols.SoapException ex)
{ throw MyWizardException(ex);
}
}
}
public class MyWebService :
System.Web.Services.Protocols.SoapHttpClientProtoc ol
{
//etc...
}
any ideas what I am missing here?
Please advise. thanks!!