consume php soap webservice in winform c# - c#

one of my friend made a soap webservice in PHP and now i have to consume it into my winform app. I added web Service Reference , pasted the URL and it is showing method name.
The method name is Display().
Now after adding when write code on button click, it is showing following three methods:
MyWebServiceName. DisplayCompletedEventArgs
DisplayCompletedEventHandler
SiteControllerService
There is no soapClient or direct Display method ,any one know , what am I doing wrong?

Check the WSDLyou must have in the VS project. You will find the service name:
Ex:
<wsdl:service name="SiteControllerService">
So you must type:
MyWebServiceName.SiteControllerService SOAPclient = new MyWebServiceName.SiteControllerService();
SOAPClient.Display();
Visual Strudio create a namespace to encapsulate all classes generated to work with the web service. In that namespace you will find the soap proxy client, events and events handler and any data transfer object needed to pass parameters to proxy client or to recive the response.

Related

How to fetch data from WSDL in C#?

I need to consume a service endpoint which is WSDL.
I tried adding it as a webreference and service reference. In both occasions I couldn't find an effective method to fetch data.
Below is the service consumed in SoapUI -
When you added ServiceReference, it would have created a Client\Proxy Class as well. This client in actual serializes the data into soap format, sends it over the network and then deserializes the soap response into memory response objects which you can consume
when you do a "Add Service Reference", on the dialog that comes up, click on the [Advanced] button in the button left corner and on the next dialog that comes up, pick the [Add Web Reference] button at the bottom.
Notice that there is a namespace, have you included that namespace in the class that is calling the web service
That namespace should contain a client class that will allow you to invoke the web service
I could consume this service by creating the client object and calling the method from client.

Call a soap client's method using a string and an object

I'm using an external open source project that provides me computation services that I create using a UI that it provides.
The project creates web-service endpoints automatically that I'm suppose to consume via my application.
My problem is that I can't interfere in the process. It's a black box that creates a service for me when I choose to deploy the project.
Each service has a bunch of different logical "private methods" that are exposed in the wsdl that's automatically created.
If I could create the service myself, I would create one an interface with an exposed method called Process that will have one general input request param and one general Response, something like:
public GeneralResponse Process(GeneralRequest request);
I want to create a generic out-point in my application which passes two parameters:
1.Endpoint Url to shoot the request to.
2.Generic request as an input param.
I'm using C# and the easiest way to consume a service is simply adding a service-reference, creating a client and calling the wanted method.
Since I don't want to add a client per service reference, I'll add a random one, change the client's endpoint address and shoot the request.
The problem with this approach is that the client generated will expose it's "private methods" and I don't want other programmers on my team to accidentally invoke them.
Bottom line:
Is there any elegant way to create a Generic soap client and invoke a method using a string? Similar to the way you call the Invoke method when you use reflection?
Something like this:
GenericRequest req = GetRequest();
SoapClient client = new SoapClient(endpointUrl);
GenericResponse res = client.Invoke("Process", req) as GenericResponse;

no overload method takes 2 arguments

Hi I have a WCF service and within it I have this method
void SendData(int pumpNo, List<String> pumpInfo);
however when I try to pass an int and a list into it, I get an error saying
Error 1 No overload for method 'SendData' takes 2 arguments
This is how I passed data to it in the WCF client
sendpumpdata.SendData(pumpID, pumpData);
ok so at the top I create an instance of the WCF service by doing...
ServiceReference1.iCommClient sendpumpdata = new Pumps.ServiceReference1.iCommClient();
also in my service.cs I have created the method defined in the IService.cs
A WCF web service leverages client generated code (i.e. a proxy) to communicate with the server. In your situation, even though the server code has two parameters, your client generated code must be out of date.
If you're using a Web Reference or a Service Reference just right click and Update Reference. If you're using a static WSDL then navigate to the WSDL hosted locally for the WCF service and save it to disk and then overwrite the one in your project.

Sending SOAP requests in C#

I am trying to consume a SOAP service in C#, so I added my WSDL as a Service Reference. So far, I have created an instance of the request I want to send, but I don't know how to send it, or process the response.
Can someone explain how to do this?
When you added the service reference, Visual Studio should generate some code for you, including a class for the service which is in its own namespace.
So, you need to create a new instance of this service:
var oService = new ServiceNamespace.ServiceClient();
Then you can call your methods on the service:
oService.SomeMethod();
here you can find the full documentation and sample:
http://msdn.microsoft.com/en-us/library/aa529276.aspx
Here is a full example of How you create a WebService and How to consume it. As I see you just need the part of how to consume it. But it is like a normal call function you send parameters and receieve a result parsed to an object. Sometimes Value Objects created by the Service Reference Tool. Hope it helps.
By the way it uses the Web reference, with a service reference is quite similar just the name of your Class is parsed with a SoapClient at the End, lets say that your service is named Foo, the Service reference will generate it for you like FooSoapClient

I am trying to consume a PHP SOAP service from C# and create a class wrapper in VS 2010

I've been tasked with creating a class wrapper for a SOAP service, the idea is that you'll be able to treat it as a regular class. The main reason for this is that the WDSL for the SOAP service contains only one method and it's got 5 parameters and it's only kind of OO so you'd have to know all the method calls really well and it's a bit hard to remember them all.
OK, so I've tried adding a web reference, now web references can now be added as service references in VS 2010. You click add service reference advanced etc and it puts in a service reference. Great. Unfortunately if I try and access this from a class I can't.
I can build a console app and put code in the main procedure and access the method of the SOAP service fine but when I add a reference to a class library the intellisense won't allow me to select anything. I'd instantiate an instance like so:
SOAPService.webServiceService ws = new SOAPService.webserviceService();
ws.
and then the intellisense refuses to kick in. If I do the same in a web project or a console app then I can access it fine. I've added the namespace I've done all kinds of things. Also, I can add a web reference and get a DISCO file whenever I create a web project.
OK, also while I'm on the subject I also need to pass credentials to the web service in PHP.
The problem is that in the past I'd create some .net system credentials and add these and it would usually pass through if I was connecting to another .net service.
How should I be sending them to a PHP web service? I always get either invalid username/password combo errors or envelope malformatted error types
Thanks
Mr. B
So the intellisense is not working, but if you add the method in and try to use it does it work, or produce an error?
With regard to diagnosing authentication issues try using fiddler to view the SOAP messages that are being sent, and to view the reply. Do you have some other software that connects and authenticates to that service? Use fiddler to look at the SOAP messages and compare them to see if the header is different etc.
I'd normally do it like this,
using (Service service = new Service())
{
service.ClientCredentials.Windows.ClientCredential.Domain = "domain";
service.ClientCredentials.Windows.ClientCredential.Password = "password";
service.ClientCredentials.Windows.ClientCredential.UserName = "username";
}
Also with regard to the service working or not in general use fiddler if you have any problems, you can see the SOAP messages and it often gives you a clearer message.
I know in IIS you can turn on failed request handling that also gives you an insight from what is going on at the server end, perhaps you have some form of logging too for your php service?

Categories

Resources