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.
Related
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;
I need to call a 3rd party web service from within a console application using the asynchronous method provided by their API. I'm using the old ASMX web reference way to generate a proxy.
I have a class that does the following operations and I want to create an instance of it, make the call to the service with it, but then I want to wait for the completion of the callback and only then repeat with a new instance, new call, new callback etc.
I do not want to have more than 1 call active at a time.
i.e. only 1 instance of the class will exist at a time.
The web service calling code looks like this:
using(ABCWebService service = new ABCWebService())
{
...
service.ExecuteCallAndWaitResultCompleted += service_ExecuteCallAndWaitResultCompleted;
service.ExecuteCallAndWaitResultAsync(parm1, parm2, .., stateObj);
}
...
The callback looks like this:
void service_ExecuteCallAndWaitResultCompleted(object sender, ExecuteCallAndWaitResultCompletedEventArgs e)
{
// collect data and then move onto next sequential call
}
I highly doubt there is an "asynchronous method provided by [the] API". A web method is a web method. It's your call which is asynchronous, that is to say by calling an async function on your client proxy class you tell the Framework to (in basic terms) fire off a request to this resource on another thread and call you back when it has a result. Its your client call which is asynchronous.
In Visual Studio (2012), when you Add Service Reference and then click Advanced and then Add Web Reference to create a service reference based on what VS calls "code based on .NET Framework 2.0 Web Services technology", which I gather is how you've done it, the resultant client class has not just asynchronous methods for each web method but synchronous methods too - one for each web method in the service. These synchronous methods will not return anything or yield control back to the caller until they have the result.
If I have your usage case correct, you want your console app to call the web method, wait for a response, do something once the responses arrives, and then start again. In that case, instead of calling the async method (for example GetPeopleAsync) call the synchronous method (GetPeople) - possibly inside a loop.
I want to invoke a web service from my winforms application in visual studio 2012. So, I have added a service reference to my web service in my project. This service contains two methods. How can I can invoke those methods from my c# code ?
You should be able to call it as follows:
using Your.Service.Namespace;
// ...
IYourService serviceClientInstance = new YourServiceClient();
serviceClientInstance.SomeServiceMethod();
PS: You can see info about the service and available methods by right clicking the reference (under Service References), and selecting View in object browser. Among other things, you should see a class YourServiceNameClient there, which should have been generated for you, which you can use as above.
Are web service calls synchronous or asynchronous by default? How is synchronicity determined, by the service or by the client?
I have code similar to the following:
try
{
string result = MakeWebServiceCall_1(); // this is a third party webservice
MakeWebServiceCall_2(result); // another webservice which must happen *after* the first one is complete
}
catch()
{
SetStatus(Status.Error); // this calls my own stored procedure
throw;
}
SetStatus(Status.Sucess);
In the above, SetStatus is writing to the same tables that the third party web services read from. If I change the status before both web service calls have completed, it's going to make a big mess and I'm going to get fired. How do I know/ensure that the webservice calls are synchronous?
According to MSDN when you add a reference to a Web Service it will implement methods to call the Web Service both synchronously and asynchronously in the proxy class. You just need to make sure you call the right one.
After you have located an XML Web service for your application to access by using the Add Web Reference dialog box, clicking the Add Reference button will instruct Visual Studio to download the service description to the local machine and then generate a proxy class for the chosen XML Web service. The proxy class will contain methods for calling each exposed XML Web service method both synchronously and asynchronously. Source
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.