WCF Service Reference - Getting “XmlException: Name cannot begin with the '<' character, hexadecimal value 0x3C” on Client Side

后端 未结 6 1629
醉梦人生
醉梦人生 2021-02-03 23:54

I have a smart client application communicating with its server via WCF. Data is created on the client and then sent over the service to be persisted. The server and client use

相关标签:
6条回答
  • 2021-02-03 23:54

    A similar error tripped me up, but it turned out my config file (actually a clientconfig file for silverlight) contained the following

       <<security mode="Transport">
           <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
           <message clientCredentialType="Certificate" algorithmSuite="Default" />
       </security>
    

    So sometimes messages about extra < characters should be taken literally!

    0 讨论(0)
  • 2021-02-04 00:02

    Personnally, I got the same problem with serialization of class hierarchy (not DataTables).

    My problem was not related to automatic property at all, in fact I have many. My problem was that I forgot to include reference to "System.Runtime.Serialization" in one of my dll and I also forgot to add some attributes [DataContract] on some classes referenced by upper [DataMember] attributes up in the hierarchy.

    To track my problem I started from my root class and removed some [DataMember] down the hierarchy until it pointed out the exact problem. It could takes some times depending on your hierarchy levels...

    Hope it helps! Eric

    0 讨论(0)
  • 2021-02-04 00:07

    Have a look at your DataTables (if that's what you are using to transport data).

    If the DataTable name is empty, then the Serializer might get confused and serialise things incorrectly.

    Otherwise, if you are using typed, [Serializable] objects, I have found that sometimes the Serializer also gets confused if you use dynamic property declarations, eg:

    public string MyName { get; set; }
    

    But this would be a easily repeatable error.

    0 讨论(0)
  • 2021-02-04 00:07

    Ok just came across another scenario on this one. I had a Serializable type used as a parameter for one of my Operation Contract methods.

    Commenting out this specific method from use allowed me to find the issue. In this case, the parameter was a model deserialized from a file, so I just replaced the implementation with a parameter of byte[] and ran deserialization logic at the other end.

    While not necessarily an answer for all, in the case of parameter types on your Operation Contract methods that are Serializable, you may run into this exception also. I would imagine decorating them with correct DataContract attributes would assist in rectifying this problem.

    0 讨论(0)
  • 2021-02-04 00:16

    Either use full properties with [Serializable], or use [DataContract] and [DataMember].

    The following was giving me an error, probably because .Net was creating a backing variable under the hood, with some character that the XmlSerializer didn't like.

    [Serializable]
    public class MyClass
    {
        public int MyValue { get; private set; }
        ...
    }
    

    Either create full properties

    [Serializable]
    public class MyClass
    {
        int _myValue;
        public int MyValue
        {
            get { return _myValue; }
            private set { _myValue = value; }
        }
        ...
    }
    

    Or use the DataContract and DataMember attributes

    [DataContract]
    public class MyClass
    {
        [DataMember]
        public int MyValue { get; private set; }
        ...
    }
    
    0 讨论(0)
  • 2021-02-04 00:19

    In my case, one of the classes had a property, whose datatype was object. Something like this:

    public class BuyAddOnServiceRequest
    {
        object site_id
    }
    

    after changing this to:

    public class BuyAddOnServiceRequest
    {
        string site_id
    }
    

    it worked!

    0 讨论(0)
提交回复
热议问题