[Webinar] Streamline your web hosting managementRegister Today


WebClient sending an XDocument

Posted on 2011-10-10
Medium Priority
Last Modified: 2013-12-16
I have an application which is sent an XML Document from a web page.  The idea is to act on this XML file, update it as necessary and then send the file back.  Now the initial send is done from a web page using Response.Write and is read by a C# WebClient object.  All good so far.

However I'm not sure how best to send the resultant XML file back to the web service.  I am working in a Windows Mobile 7 application and would prefer to use the WebClient object.  

I have constructed the XML file (including some embedded images as CData sections) and effectively just want to call a URL passing the XML in some form.  Obviously not as a query string but how?
Question by:ChrisMDrew
  • 3
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 36949152
I haven't done any Windows 7 development, so I am wondering why you are using the WebClient, instead of adding a web reference, and using the generated proxy to call a web method?

Author Comment

ID: 36949190
The main reason is I expect this to be ported to Android and as such I don't want to be tied into a Microsoft environment.  If I stay with WebClient / URI's that will convert easier.  Also I'm not writing the web service side of things - this is a traditional ASP web site.
LVL 96

Accepted Solution

Bob Learned earned 2000 total points
ID: 36949224
Since the web service should be able to handle HTTP POST and GET, I wouldn't see any problem with the WebClient approach.  The default web service has those options disabled, though, so you would need to check if it is enabled.

The WebClient.UploadString uses an HTTP POST.

Client.UploadString Method (String, String)

Author Comment

ID: 36987252
I have implemented the web post using the following :-

string webServiceURL = IsolatedStorageHelper.GetObject<string>("blu3server");
string page = "whereabouts_update.aspx";

// Now issue an asynchronous request to post updated data back to the server
Uri serviceUri = new Uri(webServiceURL + page, UriKind.Absolute);
WebClient webClient = new WebClient();

// Upload this to the server
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
webClient.UploadStringAsync(serviceUri ,xDocument.ToString(SaveOptions.DisableFormatting));

Which seems to work - I have a dummy .aspx file which does nothing but in the webClient_UploadStringCompleted event there are no errors returned.  My continuing problem is

1> How do I recover the posted data in the target web page
2> If there is an error how does the target web page report this to the caller?

Probably obvious but not so far to me!
LVL 96

Expert Comment

by:Bob Learned
ID: 37012883
I don't understand what you mean by " How do I recover the posted data in the target web page"...

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question