WebService error The client found that the response content type is "Application/json;charset=utf-8", but should be "text/xml".

Source: Internet
Author: User
Tags stack trace soapui wsdl

Console docking WebService normal, same method in Web project escalation error:

The client Discovery response content type is "Application/json;charset=utf-8", but should be "text/xml".
The request failed with the error message:
--
{
"Code": "03010250002",
"MSG": "Illegal JSON string",
"Data": ""
}
--.

Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code.

Exception Details: System.InvalidOperationException: The client Discovery Response content type is "Application/json;charset=utf-8", but should be "text/xml".
The request failed with the error message:
--
{
"Code": "03010250002",
"MSG": "Illegal JSON string",
"Data": ""
}
--.

Follow the online information to find the method:

1. How to override the request or response of a proxy class

In the proxy class, override the GetWebResponse method to set the contenttype of the response:

        protected OverrideSystem.Net.WebResponse GetWebResponse (System.Net.WebRequest request) {varResponse =Base.            GetWebResponse (Request); if(Response. ContentType = ="Application/json;charset=utf-8") Response. ContentType="Text/xml"; returnresponse; }                protected OverrideSystem.Net.WebResponse GetWebResponse (System.Net.WebRequest request, IAsyncResult result) {varResponse =Base.            GetWebResponse (Request,result); if(Response. ContentType = ="Application/json;charset=utf-8") Response. ContentType="Text/xml"; returnresponse; }

Debug Error:

This property is not implemented by this class.

Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code.

Exception Details: System.NotImplementedException: This class does not implement this property.

Source Error:

Line:             var response = base. GetWebResponse (request); line:             if (response. ContentType = = "Application/json;charset=utf-8") line:                 response. ContentType = "Text/xml"; Line:             return response; line:         }

Rewrite Request method GetWebResponse

        protected Override System.Net.WebRequest getwebrequest (URI uri)        {            base. GetWebRequest (URI);             " Text/xml " ;             return request;        }

The result is an error: The Client Discovery Response content type is "Application/json;charset=utf-8", but should be "text/xml".

Later debugging found that the URL is wrong, because it is the development of the command tool with VS generated proxy class, manually set the URL, set the error caused.

SOAPUI generated proxy class also should pay attention to Url,url is normal.

By the way, the method of generating the proxy class using the VS Development command tool is actually called the Wsdl.exe generation proxy class

Open VS Development Console

wsdl/language:c#/N: Namespace/out:d:/soapui_cs/class name. CS WSDL file address

Soapui generating proxy class methods



WebService error The client found that the response content type is "Application/json;charset=utf-8", but should be "text/xml".

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.