how to select FaultContractAtribute based on Name parameter

51 Views Asked by At

I have to implement interface that generates two different SystemFaults

Interface:
[ServiceContract]
public interface IErrorProvider
{
[OperationContract(Action = "getError")]
[FaultContractAttribute(typeof(string), Action = "getError", Name = "Error1Fault")]
[FaultContractAttribute(typeof(string), Action = "getError", Name = "Error2Fault")]
string getError(int iArg);
}

And implementation:

Code:
public class ErrorProvider : IErrorProvider
{
  public getError(int iArg)
  {
    if(iArg == 1)
      throw new FaultException<string>("Error1Fault","you asked err 1");
    if(iArg == 2)
      throw new FaultException<string>("Error2Fault","you asked err 2");
    return "No error";
  }
}

now when I call this service, with

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
  <Body>
    <getError xmlns="http://tempuri.org/">
        <iArg>1</iArg>
    </getError>
  </Body>
</Envelope>

I get Response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
        <faultcode>s:Client</faultcode>
        <faultstring xml:lang="fi-FI">you asked err 1</faultstring>
        <detail>
            <Error2Fault xmlns="http://tempuri.org/">Error1Fault</Error2Fault>
        </detail>
    </s:Fault>
  </s:Body>
</s:Envelope>

It shows clearly that first throw is used. What I need to get is:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
        <faultcode>s:Client</faultcode>
        <faultstring xml:lang="fi-FI">you asked err 1</faultstring>
        <detail>
            <Error1Fault xmlns="http://tempuri.org/">Error1Fault</Error1Fault>
        </detail>
    </s:Fault>
  </s:Body>
</s:Envelope> 

How to get that? And I don't have opportunity to change the other party, so somehow I need to solve this, really newbie question but I cannot find a real solution. All documents tell me to throw self made objects but I cannot understand how that's going to help as these are just error strings.

0

There are 0 best solutions below