I am getting the below error while accesssing method from WCF to DotNet
The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html>
<head>
<title>Runtime Error</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/ORSXMLWCFServiceNew' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>Runtime Error</i> </'.
Kindly help me.
I found a way how to get full response, not just useless 1024 bytes...
using (var client = new Service1Client())
{
try
{
Console.WriteLine(client.DoWork());
}
catch (ProtocolException e)
{
var webException = e.InnerException as WebException;
var responseString = webException.ExtractResponseString();
if (string.IsNullOrEmpty(responseText))
Console.WriteLine(e);
else
Console.WriteLine(responseString);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
where the following helper method is used
public static string ExtractResponseString(this WebException webException)
{
if (webException == null || webException.Response == null)
return null;
var responseStream = webException.Response.GetResponseStream() as MemoryStream;
if (responseStream == null)
return null;
var responseBytes = responseStream.ToArray();
var responseString = Encoding.UTF8.GetString(responseBytes);
return responseString;
}
See my blog for more details http://mnaoumov.wordpress.com/2012/09/28/wcf-protocolexception/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With