How to get exception information when calling JSON web service

后端 未结 2 1626
野的像风
野的像风 2021-01-21 00:09

In .NET 3.5, I had the following code:

[WebService(Namespace = \"http://kitchenpc.com/schemas/\")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
         


        
相关标签:
2条回答
  • 2021-01-21 00:47

    The exception types are not serializable. Use FaultException instead.

    throw new FaultException(..);
    
    0 讨论(0)
  • 2021-01-21 01:03

    Ah, this was a stupid issue. The exception information only appears if you have:

    <customErrors mode="Off" />
    

    In your web.config (under <system.web>). I'm actually not sure if this is a .NET 3.5 -> .NET 4.5 change in behavior, or if it got broke when I was re-writing my web.config build process using web.config transforms.

    Does anyone know if there's a way to control this on a per web-service level? I'd rather not show full debug info on normal page requests.

    Update:

    I also came to the conclusion that throwing exceptions to communicate error information from a web service is really not a good design. In fact, I wrote a post on the subject on my blog for those interested.

    0 讨论(0)
提交回复
热议问题