Creating a SOAP Service with C#

24,060

Solution 1

  1. Add a new WCF project. It should create a default Web Service (Service1) for you with a method like GetData(...) or similar.

  2. Add a second Console application project.

  3. Right-click on the Console project and select Add Service Reference.

  4. In the dialog that pops up, select the option to search the solution for services.

  5. It should find the Service1 service. Add it.

    That basically generates client-side code to call your service.

  6. Then add some code to call it to the main method of your Console project. The code will look something like this:

    var myClient = new Service1Client();

    var result = myClient.GetData(...);

  7. Right click on the Console application and select Set as Startup project.

  8. Place a breakpoint on the line where you create the Service1Client. Press the F5 key to run the code in debug mode.

    Visual studio will run your application in debug mode. It'll host the service itself. You should be able to step through the code using F10 to see how it works.

  9. When you added the service reference, and App.config will have been added to the console project. If you have a look in there it will have all of the client configuration data for connecting to the service. If you want to host your service in IIS, then you'll need to update the service endpoint URL.

Hopefully that's enough to get you up and runnning with something that works. Once you're there I'm sure you'll have many other questions.

Solution 2

I would recommend you taking a look at WCF which is the de-facto standard of creating web services on the .NET framework. And here's are some nice tutorials.

Share:
24,060
Daniel
Author by

Daniel

Updated on December 03, 2020

Comments

  • Daniel
    Daniel over 3 years

    I am nowhere near a professional level on this topic so please forgive me when I use wrong terms.

    A friend and I have been trying to create a http-based SOAP client/service for a personal project of ours.

    The language used is C#, the IDE is VS2008.

    We don't really know where and how to start. The tutorials I have found are either too advanced or are no longer usable due to VS constraints (vs2008 doesn't let me use WSE, which seemed quite nice for our purpose).

    It would be great if anyone could help us on this task.

    Regards Daniel

  • Sebastiaan Hoedeman
    Sebastiaan Hoedeman almost 7 years
    Very nice answer. Short and still clear :). I wish every answer was like this ;).