user690932
user690932

Reputation: 419

Creating SOAP message body

I would like to know how to create SOAP message, body, and envelope in C#. Any help or links appreciated.

I need to send a SOAP attachment to a third party Web Service. I don't need WCF. I know how it works. My client needs SOAP with attachment.

Upvotes: 3

Views: 5834

Answers (3)

norgie
norgie

Reputation: 51

marc_s: learn SOAP with Attachments before recommending others to learn WCF. SwA is not supported by .Net so he's got to roll his own and that is the background for his question.

Upvotes: 2

AlexanderM
AlexanderM

Reputation: 1683

Check this link out http://www.xefteri.com/articles/show.cfm?id=15 It describes process for VS.NET, but in VS2010 it is same process. This was an easiest way.

However, if you can construct SOAP message (for example, if you read WSDL and can construct message without any issues or you used something like SOAP UI (http://www.soapui.org/) to generate few mock up messages and got an idea) then you can simply do POST to that URL like in this example http://www.808.dk/?code-csharp-httpwebrequest

Upvotes: 1

marc_s
marc_s

Reputation: 754220

Here's a really super-short intro how to do this:

1) Create a new project (any kind - console app, windows app, web app - whatever) - File > New > Project

2) In your Solution Explorer, right-click on References and choose Add Service Reference

enter image description here

3) In the dialog box that pops up, you need to enter two things:

  1. your URL where the service lives (typically with a ?wsdl query string to grab the WSDL - the service description)
  2. your namespace where the service classes will live - pick whatever suits you

enter image description here

Then click on Go - this will talk to that service and see what it has to offer

4) Now, that dialog box should update, and show you the service and its operations, as discovered by Visual Studio:

enter image description here

5) Click on OK and some code gets generated in the background

6) Now instantiate a client-side proxy in your code, and call a method on it:

enter image description here

That's all you have to do - everything else, all the messy details of creating a SOAP header and message body, can be happily left to the WCF runtime.

Now go learn WCF!

Upvotes: 12

Related Questions