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