1

My company provides SOAP service over Https. I need to write a library that consumes that SOAP service using C#. I am using code generated by "Add Service Reference..." feature of Visual Studio 2008, but it creates a class for each function (there are many of them) exposed by service that i think overkill. My question is there another way to write a consumer without using "Add Service Reference..."?

Tran Thien An
  • 55
  • 2
  • 11
  • Use the above link http://stackoverflow.com/questions/5396671/how-to-send-receive-soap-request-and-response-using-c-sharp – kostas ch. Jul 30 '13 at 11:57

2 Answers2

3

You can do it by creating SOAP message and sending web request Like in this SOAP client web request

Community
  • 1
  • 1
toszo
  • 76
  • 4
  • -1 just because you _can_ do something, doesn't mean you _should_ – John Saunders Jul 31 '13 at 02:33
  • The solution in your link is a bit low-level because I must send request and parse the response by myself. I am looking for a solution that can involve creating service proxy manually but not at that low-level. – Tran Thien An Jul 31 '13 at 02:52
  • 1
    @JohnSaunders - Just because _you_ shouldn't do something doesn't mean _they_ shouldn't do it. Sure it's going to produce unexpected, hard to track down errors and will certainly result in unmanageable code... but it still is a valid solution. +1 BTW – M.Babcock Sep 21 '13 at 00:40
2

You can use svcutil.exe command line utility to create the proxy class for your service.Add that proxy class with generated config file in your project.All the service methods will be available through that class. Here are the steps for Generating proxy clas.

  1. Open Visual Studio Command prompt.

  2. Go to the specific Folder where you want to place you generated class.e.g type "cd D:\\Services

  3. run the command "svcutil.exe YourSerivceURL"

This command will generate the class for your service in "D:\\Services" folder with output.config file. you have to copy the client configration section from the output.config file and add in you web.config file where you want to refer the service.

Ishtiaq
  • 980
  • 2
  • 6
  • 21
  • I have tried as your suggestion but the generated code is similar to using "Add Service Reference" – Tran Thien An Jul 31 '13 at 02:36
  • This is not like adding service reference. Its just adding an API in your project. What if you manually create the API, even in that case you also have to add that class in your project. – Ishtiaq Jul 31 '13 at 06:28
  • If someone don't know where to find the svcutil.exe (like me), could take a look at: `C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools \svcutil.exe` https://stackoverflow.com/questions/4876374/where-is-svcutil-exe-in-windows-7 – Rohim Chou Aug 30 '20 at 14:54