Simplest way of invoking a webservice via SOAP on ASP.NET - c#

I have a webservice on a remote host that I need to invoke from ASP.NET/C# class. What is the simplest way of calling a method via SOAP, given WSDL url and a method signature?
Given:
WSDL url as string(available only at runtime, i.e. variable)
Method signature(constant)
Need to:
Create a soap client and perform method call.

The simplest thing to do is to just use "Add Service Reference" and point to the WSDL. It will generate the proxy classes for you, including a proxy method which should match the method signature you've been given.
See if you find How to Consume a Web Service to be helpful.

See here: http://msdn.microsoft.com/en-us/library/d9w023sx.aspx
Its very easy in visual studio - you simply add the web reference url and it generates the proxy stub for you.

Related

How to use SOAP service generated class methods?

I have created a SOAP service.
Now i want to consume it in a c# client application. I added the service using 'Add service reference' and service reference is added to client.
All my service entities are in service. And in current scenerio i can't move them to a common library.
Problem is, my service endpoint is accepting List<Foo> as parameter.
Foo has a method Boo.
In client, when i try to Foo.Boo() i get Cannot resolve symbol Boo error.
Unfortunately only methods on the service itself are exposed via a SOAP web service, methods on objects used as parameters or return values are not. If the method relates to a server-side operation then you could expose it at the service root level taking the instance object as parameter, or if it relates to a client-side operation you could consider adding it as a client-side extension method.

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;

how to call a web service function form a different server?

I have a web service with a import function i want to call from a c# application on another server
how do i call it
I can go to this url to invoke it:
http://site.co.uk/bespoke/WebService.asmx/Import
i want to call it from within my service on start:
protected override void OnStart(string[] args)
{
//What do i do in here?
}
You should use the Add Service Reference feature.
Your web service seems to be a SOAP service. So if you wanted to call it "manually" (without any SOAP client libraries), you would have to manually implement the protocol-level stuff (such as XML-based SOAP envelope). This is highly discouraged.
If you use the feature I mentioned above, then Visual Studio will generate classes and objects for you, so you will be able to call the web service's method via a method on a local stub class.

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

how to pass array from WinForm to WebService

How to pass array from WinForm to WebService?
Can I get any C# sample?
In Visual Studio, simply add a Web Reference or a Service Reference to your WinForm project and it will create the service proxy for you. This assumes that your WebService is exposing a WSDL file that describes the methods and parameters used.
This is a pretty broad question, and it would depend entirely on the type of web service you are looking for. Here are some instructions on how to add a Web Service reference:
Add a link to a web service
Once added, you can call whatever method requires an array and pass in the array through the parameters. A sample instantiation and method call for a web service might look like this:
MyWebService myWebServiceInstance = new MyWebService(url);
string[] params = new string[2];
myWebServiceInstance.CallArrayMethod(params);
If the web service is SOAP based, it should have a WSDL. If so, simply import a service reference to the WSDL and it will set up the proxy for you. Then you create an array and pass it to the method in question.
If you are talking REST based services, I would look at the RestBucks implementation on CodePlex (http://restbucks.codeplex.com/). You will want to look at the client side code. It will show you how to add your "array" in the call body, while setting up header information, etc.
Worst case is going down to a lower level and creating your own Request object. Most likely that would be overkill.

Categories

Resources