Implementing a SOAP client in C # with WCF and .NET 4.0

I am having problems running WCF in .NET 4.0. This is my situation:

I created a small SOAP server in PHP. I have a C # project in which I want to connect to this server and initiate a SOAP connection.

My problem is that I do not know how to do this in C #. I can not find the correct introduction to WCF. There are ways to do this. But I can’t find the classes and links I need to add to my C # project. Are there any tutorials on how to achieve this in C #? I searched a lot and found nothing that helped me.

I want to download the WSDL from my SOAP server at runtime, make a SOAP request, get a response and execute it. But where can I start? The MSDN website about WCF only confuses me.

Change There is probably no need to retrieve the WSDL file at run time. So no longer needed.
I used svcutil to create the class and embedded it in my project. I have not been able to test it yet, because I have some problems with the MySQL database (it is running and accessible from the mysql or mysqladmin command line, but I cannot connect to it using any other program ...), I will send a report as soon as I find out if it works.

Change 2 . I followed Kevs approaches, and in the end it turned out to be very good. My last problem was that I used the service class in the DLL. I needed app.config in a program that also used a DLL. After I did this, everything worked out well.

+6
source share
1 answer

The fastest way to do this is to right-click β€œAdd Service Link” in your client project in the β€œLinks” section. Direct the dialog to the location of the WSDL and click Go:

enter image description here

The URL I used was for the style of the .NET helpdesk, you will need to replace everything your PHP SOAP service uses to open its WSDL.

Doing this will create a proxy server on the client side, which you can create to communicate with your web service.

To access the service, you can do something like (although your particular implementation will not be the same):

MyService.MyWebServiceSoapClient ws = new MyService.MyWebServiceSoapClient(); string result ws.DoThing(); 

Pay special attention to the SoapClient part of the proxy class name, this is added to the name of the soap program name by the proxy generator.

The proxy generator will also create all the necessary configurations in your web.config or app.config .

+8
source

Source: https://habr.com/ru/post/887910/


All Articles