Search code examples
wcfwcf-ria-services

Trouble passing XML text to RIA Services from my client


I am trying to pass the following XML text to RIA services in a query operation that returns a queryable sequence of entities in response:

<?xml version="1.0" encoding="utf-8"?>
<project>
    <item type="Item" filetype="cabinet" category="EZ Workshop" name="EZW Panel Edge-Banded" height="24.000000" width="36.000000" depth="0.725000" quantity="1">
    </item>
    <item type="Item" filetype="cabinet" category="EZ Furniture" name="Entry Bench" height="19.000000" width="48.000000" depth="17.999999" quantity="1">
    </item>
    <item type="Item" filetype="cabinet" category="EZ Closet Euro Style" name="CSEKD Tall H3R 28-72W 12-24D" height="84.000000" width="54.000000" depth="19.999999" quantity="1">
    </item>
    <item type="Item" filetype="assembly" category="EZ Pro ManCave" name="EZ Corn Hole Game-Set" height="0" width="0" depth="0" quantity="1">
    </item>
    <item type="Item" filetype="assembly" category="EZ Office" name="EZ 30 Printer Stand" height="0" width="0" depth="0" quantity="1">
    </item>
    <item type="Item" filetype="assembly" category="Corporate Culture Pro" name="C-Table" height="0" width="0" depth="0" quantity="1">
    </item>
</project>

This is the query operation:

[Query]
public IQueryable<ProjectItem> GetItemsFromImport(String a_strImportXml)
{
    // Return empty sequence for now as a test.
    return new ProjectItem[0].AsQueryable();
}

When I pass the full XML, I get that annoying "Not Found" exception, and the break-point in my operation is never hit. I'm using Visual Studio 2010's ASP.NET Development Server. When I get "Not Found" with that it portends bad stuff. The kicker is, when I pass an empty string, I get no exceptions at all, and the break-point is hit.

As you can see its not a tremendously long XML document. Is there some limit to the amount of data sent? Do I have to escape the document?

Thanks.

Edits:

I discovered that I only had to escape the structural characters ('<', '>', and '&') out of the document before I sent it. I'm using String.Replace to do it. Does anyone know if there is a better way to accomplish this. Something similar to Uri.EscapeDataString perhaps?

var strImportXml = a_xImport.ToString();
strImportXml = strImportXml.Replace("&", "&amp;");
strImportXml = strImportXml.Replace("<", "&lt;");
strImportXml = strImportXml.Replace(">", "&gt;");

Solution

  • Ok, so I guess this is standing as the answer to my own question. I discovered that I only had to escape the structural characters ('<', '>', and '&') out of the document before I sent it. I'm using String.Replace to do it. Does anyone know if there is a better way to accomplish this. Something similar to Uri.EscapeDataString perhaps?

    var strImportXml = a_xImport.ToString();
    strImportXml = strImportXml.Replace("&", "&amp;");
    strImportXml = strImportXml.Replace("<", "&lt;");
    strImportXml = strImportXml.Replace(">", "&gt;");
    

    NOTE: I'd still like to know if there is a better way to do this.