Define Correspond Fault for the Soap Exception in the WSDL

H

huohaodian

Hi,

I am planning to use a custom wsdl for my web service, it seems
that the SoapException class provides nice and easy way to handle soap
exception on the server side. Corresponding to the associated fault
definition in the wsdl, how should I define the fault element that
corresponds to the exception SoapException may be raised from server
with message, code, actor and detail?

Thanks in advance.
 
J

John Saunders

Hi,

I am planning to use a custom wsdl for my web service, it seems
that the SoapException class provides nice and easy way to handle soap
exception on the server side. Corresponding to the associated fault
definition in the wsdl, how should I define the fault element that
corresponds to the exception SoapException may be raised from server
with message, code, actor and detail?

You simply define the structure of the detail section using XML Schema.
Then, refer to it in the <wsdl:message> element that defines the fault
message. Refer to the fault message in the <wsdl:fault> section using the
type attribute.

Then, all you have to do is construct an instance of your fault detail and
provide it to the SoapException constructor.

I don't have time to find or create an example today, but let me know if
you're still stuck after this and I'll try to make time.
 
H

huohaodian

You simply define the structure of the detail section using XML Schema.
Then, refer to it in the <wsdl:message> element that defines the fault
message. Refer to the fault message in the <wsdl:fault> section using the
type attribute.

Then, all you have to do is construct an instance of your fault detail and
provide it to the SoapException constructor.

I don't have time to find or create an example today, but let me know if
you're still stuck after this and I'll try to make time.


Thank you so much John.

I am still struggling... is it possible you could give me a little
sample?

Thanks again.
 
H

huohaodian

You simply define the structure of the detail section using XML Schema.
Then, refer to it in the <wsdl:message> element that defines the fault
message. Refer to the fault message in the <wsdl:fault> section using the
type attribute.

Then, all you have to do is construct an instance of your fault detail and
provide it to the SoapException constructor.

I don't have time to find or create an example today, but let me know if
you're still stuck after this and I'll try to make time.

I have created structure for the detail section

<s:complexType name="detail">
<s:sequence>
<s:element name="ErrorCode" type="s:int"/>
<s:element name="Message" type="s:string"/>
</s:sequence>
</s:complexType>

then added a message
<wsdl:message name="FaultError" type="tns:detail"/>

then added fault to the operation
<wsdl:fault name="FaultName" message="tns:FaultError"/>

and then after adding <soap12:fault name="FaultName" use="literal"/>
in the soap 12 section, the editor stopped to complain.

On the server side, I follow the sample to raise the exception with
something like
XmlDocument doc = new XmlDocument();
XmlNode detail = doc.CreateNode(XmlNodeType.Element,
SoapException.DetailElementName.Name,
SoapException.DetailElementName.Namespace);

XmlNode errorType = doc.CreateNode(XmlNodeType.Element,
"ErrorCode", myNS);
errorType.InnerText = "-1";

XmlNode lineNum = doc.CreateNode(XmlNodeType.Element,
"Message", myNS);
lineNum.InnerText = "Error";


detail.AppendChild(errorType);
detail.AppendChild(lineNum);


string errorMsg = "An error was received while processing the
message (see Detail element for more information)";
SoapException exc = new SoapException(errorMsg,
SoapException.ClientFaultCode, "", detail);
throw exc;

Anything I should pay attention on the "Fault Name" in the <wsdl:fault
name="FaultName" message="tns:FaultError"/>?
What is the correspondence between soap exception details and this
FaultName?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top