Results 1 to 5 of 5

Thread: Strange Characters from Web Service Output - Data Dependent...

  1. #1

    Thread Starter
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Exclamation Strange Characters from Web Service Output - Data Dependent...

    Hi All

    I'm busy writing an Application that makes extensive use of Web Services. Everything seems to be working fine, aside from "non-standard" characters appearing as question marks depending on the size of the return object.

    I can see a value come through containing an apostrophe. In Wireshark it shows as "\342\200\231", and when pulled through to my application it shows an apostrophe correctly. However, when I get a bigger set of data through the web service, it seems to improperly "decode" the value such as "Photo's" as "Photo???s"...

    The exact same data is shown in Wireshark though, which leads me to believe that C# somehow incorrectly converts the response?

    I removed the DebuggerStepThroughAttribute from Reference.cs to debug the actual web service code and I placed a breakpoint on the method that I invoke to get the return data, and adding the Output object to the QuickWatch also shows the data containing question marks instead of the correct data as well.

    I can copy and paste the raw XML directly into an XML editor and the data shows correctly.

    The method that I invoke returns an array of a Complex type. (see below) Could this be the cause of it?

    The "Complex Type" array that I get out only has four fields and is basically defined as follows:
    Code:
    public partial class QueryResults
    {
            private string rowNumberField;
            private string fieldNameField;
            private string fieldValueField;
            private string fieldFormattedValueField;
            ...
            ...
            ...
    }
    Unfortunately I can't control how the XML is encoded from the "host" Web Service, as this is "black box" functionality in our Host Application.

    Any help anyone can offer will be greatly appreciated!

  2. #2

    Thread Starter
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Re: Strange Characters from Web Service Output - Data Dependent...

    Did a bit more scratching:

    I copied the input data from Wireshark into an XML file and invoked the same url using HttpWebRequest. When I "manually" invoke the web service, the return data is shown as expected. The problem only occurs when using the C# generated classes.

    Any ideas?

    Here's what I did to test:
    Code:
    public Service_Outputs QueryTest(Service_Inputs inputs)
    {
    	Service_Outputs ret = new Service_Outputs();
    	HttpWebRequest req = (HttpWebRequest)WebRequest.Create(cGlobals.WSUrl);
    	req.Headers.Add("SOAPAction: \"" + soapAction + "\"");
    
    	req.ContentType = "text/xml;charset=\"utf-8\"";
    	req.Accept = "text/xml";
    	req.Method = "POST";
    	
    	Stream stm = req.GetRequestStream();
    	XmlDocument doc = new XmlDocument();
    	doc.InnerXml = CreateQueryDoc(inputs); // Method will load text file
    	doc.Save(stm);
    	stm.Close();
    
    	WebResponse resp = null;
    	try
    	{
    		resp = req.GetResponse();
    	}
    	catch (WebException e)
    	{
    		WebResponse ex = e.Response;
    		HttpWebResponse http = (HttpWebResponse)ex;
    		string totalMsg = http.StatusCode.ToString() + "\n";
    
    		for (int i = 0; i < http.Headers.Count; i++)
    		    totalMsg += http.Headers.GetKey(i) + " : " + http.Headers.Get(i) + "\n";
    	}
    	if (resp != null)
    	{
    		stm = resp.GetResponseStream();
    		StreamReader r = new StreamReader(stm);
    
    		string total = r.ReadToEnd();
    		ret = DeserializeObjectFromXML(total);
    	}
    	return ret;
    }
    As mentioned, the "ret" object holds the correct data.

  3. #3
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: Strange Characters from Web Service Output - Data Dependent...

    Could it be that the encoding isn't correct (maybe UTF-16 in stead of UTF-8)...
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  4. #4

    Thread Starter
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    Re: Strange Characters from Web Service Output - Data Dependent...

    I... have no idea. I checked the response and it's sending UTF-8 as a header. How can I confirm that the content received has the same encoding as specified in the header?

  5. #5
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: Strange Characters from Web Service Output - Data Dependent...

    You could put the resonse in notepad++ that checks the encoding automatically
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width