简体   繁体   中英

Passing CDATA in a parameter with XML-RPC.NET

I'd like to call a method of a XML-RPC web service with a XML request containing the following fragment:

<member>
  <name>filters</name>
  <value><![CDATA[
    <filterinstances>
      <filterinstance type="date" comparison="equals">today</filterinstance>
    </filterinstances>
  ]]></value>
</member>    

To do this, I use a XML-RPC.net proxy and I pass the filters parameter as a string:

IGetReportData proxy = XmlRpcProxyGen.Create<IGetReportData>();

proxy.Url = "<* my url >*";
proxy.KeepAlive = false;
proxy.UseStringTag = false;

ReportDataParams rp = new ReportDataParams();
rp.show = "3";
rp.filters = "<![CDATA[<filterinstances><filterinstance type=\"date\" comparison=\"equals\">today</filterinstance></filterinstances>]]>";

string s = proxy.GetReportData("test", rp);

The ReportParams is defined as a struct.

public struct ReportDataParams
{
    public string show;
    public string filters;
}

The trouble is that XML-RPC.Net decodes the XML within the filters string. The following fragment is sent to the server:

      <member>
        <name>filters</name>
        <value>
          <string>&lt;![CDATA[&lt;filterinstances&gt;&lt;filterinstance type="date" comparison="equals"&gt;today&lt;/filterinstance&gt;&lt;/filterinstances&gt;]]&gt;</string>
        </value>
      </member>

Is there any way to pass the CDATA xml fragment literally as a parameter to XML-RPC.Net?

I had similar trouble. The solution for me was to just rip out all the CDATA stuff. In your example, you'd just pass:

<filterinstances><filterinstance type=\"date\" comparison=\"equals\">today</filterinstance></filterinstances>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM