locked
Expecting state 'Element'.. Encountered 'Text' with name '', namespace '' RRS feed

  • Question

  • I am using WCF - webHttpBinding to invoke a REST API (SQL Azure Management API)

    http://msdn.microsoft.com/en-us/library/gg715274

    The response is in the form of 

    <ServerName>string</ServerName>

    My Operation contract is as follows:

     [WebInvoke(Method="POST", UriTemplate=@"{subscriptionId}/servers")]
            ServerName CreateServer(string subscriptionId, CreateServerInput input);


    My Data contracts are as follows:

       [DataContract(Name = "Server", Namespace = "http://schemas.microsoft.com/sqlazure/2010/12/")]
        public class CreateServerInput : IExtensibleDataObject
        {
            [DataMember(Order = 1)]
            public string AdministratorLogin { get; set; }
    
            [DataMember(Order = 2)]
            public string AdministratorLoginPassword { get; set; }
    
            [DataMember(Order = 3)]
            public string Location { get; set; }
    
    
            public ExtensionDataObject ExtensionData { get; set; }
        }
        [DataContract(Name = "ServerName", Namespace = "http://schemas.microsoft.com/sqlazure/2010/12/")]
        public class ServerName :  IExtensibleDataObject
        {
            //[DataMember(Name="")]
            //public string Text { get; set; }
    
            public ExtensionDataObject ExtensionData { get; set; }
        }

    I am not sure how to represent the response - Servername as a Datacontract. As a result, I am getting a SerializationException with the message - Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''

    Any pointers on how to resolve this?

    Friday, May 18, 2012 9:17 AM

All replies

  • I am able to do this if I use XmlSerializerFormat, and use [XmlText] for the property Text within ServerName. 

    I like to know if it is possible to do this using DataContractSerializer.

    Friday, May 18, 2012 9:51 AM