Link to home
Start Free TrialLog in
Avatar of ChrisMDrew
ChrisMDrew

asked on

WebClient sending an XDocument

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?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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?
Avatar of ChrisMDrew
ChrisMDrew

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
I don't understand what you mean by " How do I recover the posted data in the target web page"...