0

我必须实现生成两个不同 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);
}

和实施:

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";
  }
}

现在,当我调用此服务时,使用

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

我得到回应:

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

它清楚地表明使用了第一次投掷。我需要得到的是:

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

如何得到它?而且我没有机会改变对方,所以我需要以某种方式解决这个非常新手的问题,但我找不到真正的解决方案。所有文件都告诉我扔自制的物体,但我不明白这会有什么帮助,因为这些只是错误字符串。

4

0 回答 0