Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:32:28+00:00 2026-06-09T06:32:28+00:00

I need to send an XML message to a web service for my WP7

  • 0

I need to send an XML message to a web service for my WP7 app, but I have no experience doing that.

This is the format in which the web service needs me to send the XML:

<pfpMessage version='1.5'>
 <header>
    <source>
      <component type="pfsvc" role="master">
        <host ip="" hostname="" serverId=""/>
      </component>
    </source>
  </header>
  <request request-id='1288730909' async='0' response-url='' language='en'>
    <phoneAppValidateDeviceTokenRequest >
      <phoneAppContext >
        <guid>...</guid>
        <deviceToken >...</deviceToken>
        <version >1.0.0</version>
      </phoneAppContext>
      <validationResult >yes</validationResult>
    </phoneAppValidateDeviceTokenRequest>
  </request>
</pfpMessage>

And this is a small section of the code I have written:

    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);

Part of the problem is that the SetAttributeValue function keeps throwing an exception even though it looks exactly the same as the MSDN example.

Is this the right way to build an XML message that matches the format?

EDIT: This causes an InvalidOperationException:

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")
                )                   
        );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:32:33+00:00Added an answer on June 9, 2026 at 6:32 am

    Here:

    XElement root = doc.Element("pfpMessage");
    root.SetAttributeValue("version", 1.5);
    

    … you’re assuming that the element already exists. The Element method finds an element in the container you call it on. You’ve only just created the document, so it’s empty. You need to create a new element:

    XElement root = new XElement("pfpMessage");
    

    Likewise everywhere else.

    Here’s a clearer way of doing it:

    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)
                        )
                    )
                )
            )
        )
    );
    

    (Obviously you can collapse the brackets at the end if you want.)

    This is a more declarative way of constructing the document – it’s closer to the spirit of LINQ to XML. Of course you can manually create each element separately and attach it to the parent, but it’s more long-winded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create xml message and send it to the web service. Then
I have a wide-character XML message that I need to send over a Win32
I have a web service that I need to consume from BizTalk orchestration. I've
I need to send this XML <?xml version=1.0 encoding=UTF-8?> <gate> <country>NO</country> <accessNumber>1900</accessNumber> <senderNumber>1900</senderNumber> <targetNumber>4792267523</targetNumber>
i have a scenario where in i need to send an xml as a
HI I have an xml file with 500KB size which i need to send
I have an XML file which I need to parse using PHP and send
I need to send a SOAP request to a URL. But i find this
I have a web service outside of my company that provides no WSDL for
There is a self hosted WCF REST service, need to send an xml post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.