How to solve the problem that the client webchannelfactory cannot handle the exception thrown by webfaultexception in WCF rest?

Source: Internet
Author: User

Webchannelfactory can be used in the net to easily construct the client for using WCF rest, but there is a problem at this time, that is, when our server has some errors,
For example, if the verification succeeds, but we want to throw a custom exception message (which is the same message class), we will find that the client cannot process it.

He will appear

Unable to deserialize XML body with root name 'errormess' and root namespace ''(for Operation 'get' and contract ('iservice1 ', 'HTTP: // tempuri.org /')) using datacontractserializer. ensure that the type corresponding to the XML is added to the known types collection of the service.

Such an error,

At this time, we can improve the client so that all our entity classes inherit from this message class, so that everything is okay.

But there is no way for list <> and void.
We will use

[Serviceknowntype (typeof (list <sampleitem>)] and dynamic return classes get the expected results.

 

But the best way is to implement such a process by writing a webchannelfactory (which is actually a proxy to work) similar class to how to customize the proxy http://www.cnblogs.com/lovebanyi/archive/2011/02/22/1961258.html.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.