The. NET client of the WCF data service does not support service operation calls with the return value of the native type (string, INT). For example, we use the following service operations:
[Webget]
Public objectquery <string> getlist (string entityset, string propertyname)
{
Return this. currentdatasource. createquery <string> (string. format ("select value e. {1} from myentities. {0} as E ", entityset, propertyname )). distinct ();
}
Use the following method to call
Myentities. createquery <string> ("getlist"). addqueryoption ("entityset", "'test '")
. Addqueryoption ("propertyname", "'test'"). beginexecute (....);
An error occurs:
Error Processing response stream. The XML element contains mixed content.
At system. Data. Services. Client. materializeatom. readelementstring (Boolean checknullattribute)
At system. Data. Services. Client. materializeatom. readnext (clienttype currenttype, type expectedtype, atomparsestate atom, entitystates & entitystate, object & currentvalue)
At system. Data. Services. Client. materializeatom. movenext ()
At system. Collections. Generic. List '1 .. ctor (ienumerable '1 collection)
At system. LINQ. enumerable. tolist [tsource] (ienumerable '1 source)
Solution:
When you use httpwebrequest to request the rest service, the service returns data in atom format similar to the following and performs operations through LINQ to XML:
<Serviceopname xmlns = "http://schemas.microsoft.com/ado/2007/08/dataservices">
<Element XML: Space = "preserve"> value </element>
...
</Serviceopname>
VaR q = myentities. createquery <string> ("getlist"). addqueryoption ("entityset", "'test '")
. Addqueryoption ("propertyname", "'test '");
WebClient WC = new WebClient ();
WC. downloadstringasync (New uri (Q. tostring (); WC. downloadstringcompleted + = (S, e) =>
{
Xdocument xdoc = xdocument. parse (E. Result );
List <string> List = xdoc. Root. descendants (xnamespace) @ "http://schemas.microsoft.com/ado/2007/08/dataservices") + "element ")
. Select (Xe => Xe. Value). tolist ();
};