none
Getting an XmlException First Time Calling WCF Service RRS feed

  • Question

  • I have created a WCF web service, and I am calling from a standard asp.net (non-MVC) web page. The first time it is called during a session, it returns the following error:
    "CData elements not valid at top level of an XML document.  Line 1, position 3"

    After that initial failure, all WCF calls succeed.   I tried the same service from a winforms application, and the same thing happens.   I did setup logging, and there were no explanations of the bad xml being generated.

    Any suggestions would be appreciated.

    Steve

    Friday, September 20, 2013 9:04 PM

Answers

  • Hi,

    It seems that this error may occur when the content of the xml containing some "html tags" or some special character like "", "/", ...that could break the Xml schema. So please encode any html content before adding them to the Xml.

    Or maybe you have used transferMode=STREAMED in the configure file. If so please try to remove that.

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 2:14 AM
    Moderator
  • Hi Steve,

    As for the WCF service, would you provide some more information such as what is the ServiceContract and operation contract look like and what kind of data will you return from the service operation? Also, are you using HTTP as the transport? If so, you can try using fiddler or other HTTP debugging tools to capture the request and response messages of the service operation call so as to check what is the difference between the initial request and sequential operation calls.

    #Install Fiddler
    http://fiddler2.com/get-fiddler


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 7:16 AM
    Moderator

All replies

  • Hi,

    It seems that this error may occur when the content of the xml containing some "html tags" or some special character like "", "/", ...that could break the Xml schema. So please encode any html content before adding them to the Xml.

    Or maybe you have used transferMode=STREAMED in the configure file. If so please try to remove that.

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 2:14 AM
    Moderator
  • Hi Steve,

    As for the WCF service, would you provide some more information such as what is the ServiceContract and operation contract look like and what kind of data will you return from the service operation? Also, are you using HTTP as the transport? If so, you can try using fiddler or other HTTP debugging tools to capture the request and response messages of the service operation call so as to check what is the difference between the initial request and sequential operation calls.

    #Install Fiddler
    http://fiddler2.com/get-fiddler


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 7:16 AM
    Moderator