I'm having trouble getting started with WCF in .NET 4.0. This is my situation:
I have created a small SOAP Server in PHP. I have a C# project in which I want to connect to this Server and initiate the SOAP communication.
My problem is, I have no idea how to do this in C#. I can't find the right introduction to WCF. There are ways to do this. But I can't find the right classes and references to add to my C# project. Are the any tutorials how to achieve this in C#? I searched a lot and found nothing which helped me.
I want to load the WSDL from my SOAP Server at run time, make the SOAP request, retrieve the answer and be done. But where can I get started? The MSDN site about WCF is only confusing me more.
Edit: It probably is not necessary to fetch the WSDL file at run time. So that is not needed anymore.
I used svcutil to create the class and embedded it in my project. I haven't been able to test it yet, because I have some trouble with the MySQL database (It's running and accessible from the mysql command line tool or mysqladmin, but I can't connect to it with any other programm...). I'll report back as soon as I know if it works.
Edit 2: I've followed Kevs approach and it worked out very good in the end. My final problem was, that I used the Service Class in a DLL. I needed the app.config in the programm which used the DLL too. After I did that it worked out well.
A SOAP message is encoded as an XML document, consisting of an <Envelope> element, which contains an optional <Header> element, and a mandatory <Body> element. The <Fault> element, contained in <Body> , is used for reporting errors.
SOAP (formerly a backronym for Simple Object Access Protocol) is a messaging protocol specification for exchanging structured information in the implementation of web services in computer networks.
To make SOAP requests to the SOAP API endpoint, use the "Content-Type: application/soap+xml" request header, which tells the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a "Content-Type: application/soap+xml" response header.
SOAP (Simple Object Access Protocol) is a simple solution for interaction of different applications built in different languages and running on different platforms as it uses HTTP as its transport and XML as its payload for sending and receiving messages.
The quickest way to do this is to do right-click "Add Service Reference" in your client's project under References. Point the dialogue at the location of the WSDL and click Go:
The URL I used was for the style of a .NET service reference, you'll need to replace with whatever your PHP SOAP service uses to expose its WSDL.
Doing this will generate a client side proxy you can instantiate to communicate with your web service.
To access the service you can then do something like (although your specific implementation won't be the same):
MyService.MyWebServiceSoapClient ws = new MyService.MyWebServiceSoapClient();
string result ws.DoThing();
Pay particular attention to the SoapClient
part of the proxy class name, this is added to the name of the soap service name by the proxy code generator.
The proxy generator will also create all the necessary configuration in your web.config
or app.config
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With