English 中文(简体)
WCF 退回JSON-formatted 过错的服务
原标题:WCF service to return JSON-formatted faults
  • 时间:2010-07-14 11:16:18
  •  标签:
  • c#
  • wcf
  • json

是否有可能让妇女和家庭福利服务机构将过失退回客户? 我因此认为,在使用《行动计划》时,这样做是可能的,但我愿意返回。

理想的情况是,《吉大港山区行动计划》的应对法将适用于表明发生错误的一些内容,然后,将在JSON的答复中提供问题的细节。

目前,我做的是:

[ServiceContract]
public class MyService
{
    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    [FaultContract(typeof(TestFault))]
    public MyResult MyMethod()
    {
        throw new FaultException<TestFault>(new TestFault("Message..."), "Reason...");
    }
}

looks:

[DataContract]
public class TestFault
{
    public TestFault(string message)
    {
        this.Message = message;
    }

    [DataMember]
    public string Message { get; set; }
}

目前,在服务配置中没有任何特别的特殊之处。

结果是400份Bad Request的回复,有超文本格式的错误。 (当IincludeExceptionDetailInFaults时,我可以看到“FaultException的理由和细节,但没有关于的详细说明。)

当有人投掷<代码>Exception(或FaultException时,网络服务将JSON ok送回。

任何建议?

最佳回答
问题回答

你们所需要的一切都有可能从......开始。 NET 4. See here。 例如:

throw new WebFaultException<string>(
    "My error description.", HttpStatusCode.BadRequest); 

阁下的“ j!

error: function (xhr, status, error) {
  var responseObj = JSON.parse(xhr.responseText);
  alert( Request failed with error: "  + responseObj.Message);
}

在您的WCF服务处,对网络FaultException建筑商例外。 你的习俗信息将通过应急行动获得。 上文javascript的电文:

public class AJAXService : IAJAXService
{
  public void SomeMethod()
  {
    throw new WebFaultException<Exception>(new Exception("some custom error message!"), HttpStatusCode.InternalServerError);
  }
}   




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签