views:

243

answers:

2

I have been trying to find some step by step guidance on how to take a user's inputs (e.g.) name address, etc) via the view, to write that to xml, and then to submit that set of data to a third party interface (e.g UK Companies house xml gateway)

I have some aspects in hand (i.e. GET side of view to collect the data), but can't seem to get my head around using the controller and POST to submit the actual thing!

If anyone can steer me to a "For dumboids" tutorial, I'd highly appreciate it

Thanks

Paul

A: 

I would question whether the controller should be posting directly to the XML gateway - this sounds like the job of a domain/business object sitting behind the controller, ideally referenced by an interface.

This was you can test your controller without requiring it to hit the XML gateway, and simulate the success/failure conditions.

If you can get the data already, I'd consider:

IGatewayPoster poster = ...
poster.Submit(dataSentFromView);

In the GatewayPoster class do the actual work of communicating with the XML gateway.

Michael Shimmins
A: 

Side stepping the issue of whether you should be posting from your controller, you can use code like the following to post xml to a url. In the example below "xml" is your xml string and "url" is the url you want to post to. (Note: WebClient is built-into the .NET framework)

// create a client object
using(System.Net.WebClient client = new System.Net.WebClient()) {
    // performs an HTTP POST
    client.UploadString(url, xml);  

}
User