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?
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?
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have implemented the web post using the following :-
string webServiceURL = IsolatedStorageHelper.GetO bject<stri ng>("blu3s erver");
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.UploadStringComp leted += new UploadStringCompletedEvent Handler(we bClient_Up loadString Completed) ;
webClient.UploadStringAsyn c(serviceU ri ,xDocument.ToString(SaveOp tions.Disa bleFormatt ing));
Which seems to work - I have a dummy .aspx file which does nothing but in the webClient_UploadStringComp leted 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!
string webServiceURL = IsolatedStorageHelper.GetO
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.UploadStringComp
webClient.UploadStringAsyn
Which seems to work - I have a dummy .aspx file which does nothing but in the webClient_UploadStringComp
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"...