Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7 - Building an XML Message
    primarykey
    data
    text
    <p>I need to send an XML message to a web service for my WP7 app, but I have no experience doing that. </p> <p>This is the format in which the web service needs me to send the XML: </p> <pre><code>&lt;pfpMessage version='1.5'&gt; &lt;header&gt; &lt;source&gt; &lt;component type="pfsvc" role="master"&gt; &lt;host ip="" hostname="" serverId=""/&gt; &lt;/component&gt; &lt;/source&gt; &lt;/header&gt; &lt;request request-id='1288730909' async='0' response-url='' language='en'&gt; &lt;phoneAppValidateDeviceTokenRequest &gt; &lt;phoneAppContext &gt; &lt;guid&gt;...&lt;/guid&gt; &lt;deviceToken &gt;...&lt;/deviceToken&gt; &lt;version &gt;1.0.0&lt;/version&gt; &lt;/phoneAppContext&gt; &lt;validationResult &gt;yes&lt;/validationResult&gt; &lt;/phoneAppValidateDeviceTokenRequest&gt; &lt;/request&gt; &lt;/pfpMessage&gt; </code></pre> <p>And this is a small section of the code I have written:</p> <pre><code> XDocument doc = new XDocument(); // start message XElement root = doc.Element("pfpMessage"); root.SetAttributeValue("version", 1.5); doc.Add(root); // message header XElement header = doc.Element("header"); root.Add(header); XElement source = doc.Element("source"); header.Add(source); XElement component = doc.Element("component"); component.SetAttributeValue("type", "pfsdk"); source.Add(component); XElement element = doc.Element("host"); element.SetAttributeValue("ip", pfAuthParams.IpAddress); element.SetAttributeValue("hostname", pfAuthParams.Hostname); component.Add(element); </code></pre> <p>Part of the problem is that the SetAttributeValue function keeps throwing an exception even though it looks exactly the same as the MSDN example. </p> <p>Is this the right way to build an XML message that matches the format?</p> <p>EDIT: This causes an InvalidOperationException:</p> <pre><code>XDocument doc = new XDocument( new XElement("pfpMessage", new XAttribute("version", 1.5), new XElement("header", new XElement("source", new XElement("component", new XAttribute("type", "pfsdk"), new XElement("host", new XAttribute("ip", pfAuthParams.IpAddress), new XAttribute("hostname", pfAuthParams.Hostname) ) ) ) ) ), new XElement("request", new XAttribute("request-id", y), new XAttribute("async", 0), new XAttribute("response-url", ""), new XAttribute("language", "en"), new XElement("phoneAppValidateDeviceTokenRequest", new XElement("phoneAppValidateContext"), new XElement("guid", (Application.Current as App).SharedGUID), new XElement("deviceToken", (Application.Current as App).SharedURI) ), new XElement("version", "1.0.0") ) ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload