User1323099333 posted
Hi ,
We have a requirement where I need to consume a flag value returned by the webservice. for the same I have written below code .
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
WebResponse response = null;
try
{
response = httpWebRequest.GetResponse();
using (Stream stream = response.GetResponseStream())
{
System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String"));
bool translation = (bool)dcs.ReadObject(stream);
Console.WriteLine(translation);
Console.ReadKey();
}
}
And when I execute , I am seeing below mentioned exception. Could you please help me in understanding the same and suggest what need's to be done.
Error in line 1 position 77. Expecting element 'string' from namespace 'http://schemas.microsoft.com/2003/10/Serialization/'.. Encountered 'Element' with name 'ContactType', namespace
'http://url'.
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream)
at ConsumeService.Program.Main(String[] args) in C:\Users\A041448\documents\visual studio 2010\Projects\ConsumeService\ConsumeService\Program.cs:line 29
When I am calling webservice from the browser, below is the response being displayed.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <ContactType xmlns="http://URL">
<ValidationFlag>true</ValidationFlag>
</ContactType>