locked
Getting "An XML node of type 'Element' was found in a string value" calling a service operation that returns an enumerable of strings RRS feed

  • Question

  • I'm working with WCF DataServices 5.0.2.

    Following the instructions in http://msdn.microsoft.com/en-us/library/hh230677.aspx here the simple code of a repro-solution:

    Service

    public class WcfDataService1 : DataService<Database1Entities>
        {
            // This method is called only once to initialize service-wide policies.
            public static void InitializeService(DataServiceConfiguration config)
            {
                // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
                // Examples:
                // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
                // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
                config.SetServiceOperationAccessRule("ServiceOperationTest", ServiceOperationRights.AllRead);
                config.SetEntitySetAccessRule("TableA", EntitySetRights.All);
            }
    
    
            [WebGet]
            public IEnumerable<string> ServiceOperationTest()
            {
                return new string[] { "ValueA", "ValueB" };
            }
    
    
        }

    Here the client code:

    static void Main(string[] args)
            {
                var model = new Database1Entities(new Uri("http://localhost:1470/WcfDataService1.svc"));
    
                var queryString = "ServiceOperationTest";
    
                var results = model.Execute<string>(new Uri(queryString, UriKind.Relative)).ToArray();
            }

    Running this code I get the following error:

    An XML node of type 'Element' was found in a string value. An element with a string value can only contain Text, CDATA, SignificantWhitespace, Whitespace or Comment nodes.

     What's wrong? Any hints? thanks.
    Friday, October 5, 2012 5:40 PM

Answers

  • Hi,

    I consulted this issue with the product team and we found the MSDN document is incorrect.  The new Execute() overloads added on 5.0, i.e. the ones with the new “httpMethod” and “singleResult” parameters, was intended to handle non-entity collection responses when singleResult is set to false.  Currently there is a problem on ODataLib such that even with the new Execute overloads, the client will only read non-entity collection responses when the DataServiceVersion from the server is 3.0 or above.   The product team is working on this issue to fix it.

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, October 16, 2012 2:05 AM
    Moderator

All replies

  • Hi,

    Welcome to MSDN forum. 

    I can repro the issue, but I have not found the root cause of the issue.   The codes should work fine to get a collection of primitive type objects.  I will do more research and get back to you once I have any new information. 

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 8, 2012 1:25 PM
    Moderator
  • Hi,

    Im getting the same error with a service operation added to a data service,

    service operation looks like,

     [WebGet]
       public IEnumerable<string> GetMySuppliersForReference(int myReference)
        {
                        .....................

                        IEnumerable<string> results = CurrentDataSource.Suppliers_GET(myReference).AsEnumerable();

                        return results

    }

    called in unit test class to test my domain.client,

    _persistenceSession.GetMySuppliersForReference.Reference = 1111;
    _persistenceSession = new PersistenceSession(new Uri(_connectionString));
    var resultset = _persistenceSession.GetMySuppliersForReference.ExecuteEnumerable().ToList();

    can browse the data service, and query, I see the results displayed as expected, other entities in the model are being returned as expected.

    any advice greatly appreaciated.

    J

    Thursday, October 11, 2012 4:36 PM
  • Hi,

    I consulted this issue with the product team and we found the MSDN document is incorrect.  The new Execute() overloads added on 5.0, i.e. the ones with the new “httpMethod” and “singleResult” parameters, was intended to handle non-entity collection responses when singleResult is set to false.  Currently there is a problem on ODataLib such that even with the new Execute overloads, the client will only read non-entity collection responses when the DataServiceVersion from the server is 3.0 or above.   The product team is working on this issue to fix it.

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, October 16, 2012 2:05 AM
    Moderator
  • It worked for me when I converted return type of ServiceOperation from IEnumerable to IQuaryable as below      

        [WebGet]
        public IQueryable<string> ServiceOperationTest()
        {
            return (new string[] { "ValueA""ValueB" }).AsQueryable();
        }
    



    -- Jignesh Patel

    Sunday, December 9, 2012 2:41 AM
  • Hi,

    Do you know if this issue has been solved in 5.1 or 5.2 ?

    Thx

    Wednesday, January 30, 2013 10:11 PM