Synchronicity of web service calls - c#

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

Related

My web service operation call only opens test page in IIS - I am not sure how to call the operation to return my xml

I am new to web services.
I have built a web service in C# that consumes a third party service and then returns the XML response from that call in a web method.
When I test this in IIS on the local web server it works perfectly.
However when I try to call or invoke the service via the URL I use on the test page I can't return a response.
If I use a GET I simply get the test page loading and the message I can't use this test page outside of the local server.
In short, I simply want to know how to call the web method externally and mimic the INVOKE button being pressed so I get the response passed back.
This is probably really simple but I can't get my head around it.
In addition if I use Postman to try and call the URL:
WebService.asmx?op=GetSalesOrders
I get the error message detailed below which is a step forward but I am still unsure about how to package up a call to this service
You call the service by making a POST request with a properly formated SOAP message to this URL:
<path>/WebService.asmx
You get the WSDL of the web service by making a GET request to this URL:
<path>/WebService.asmx?wsdl
You can use that WSDL to build a client or test the service with something like SoapUI. See this and this for more details.
That invocation page or URLs with parameters like this:
<path>/WebService.asmx?op=GetSalesOrders
are just provided for convenience to allow you to poke at the service and make sure the service is running. They should not be used in "real" calls.

How to hide some declared Methods in ASMX file in Web Service C#

i have one doubt in Web Service / WCF
i'm creating the service and it's having 10 methods respectively
test1() , Program1(int age),Describe1(), DisplayAge(string name),,SimilarInterest(),ServiceCall(), Hide(), Difference(), WebService() and Help()
now after hosting this service in asmx only the below methods should display. others should not need to display.
DisplayAge(string name),,SimilarInterest(),ServiceCall() only these three should display when i call the http://URL.asmx?wsdl
the other 7 methods should not need to display in asmx wsdl file .how to do that?
As far as I know, in XML Web Service(ASMX), this should not work if you want the service to be both invoked and not shown in the WSDL. Either using private decorated methods or removing the [WebMethod] attribute causes the method to no longer be invoked. If in WCF we can implement authentication, authorization that individual methods cannot be invoked, or simply not expose metadata. But we cannot hide the specified method (but can be called by the outside world).
https://social.msdn.microsoft.com/Forums/en-US/533e0361-e9e0-400b-a7b2-f098a9ef3e75/how-to-prevent-web-method-from-showing-on-service-description-page?forum=asmxandxml
Feel free to let me know if there is anything I can help with.

Calling an async web service repeatedly but never concurrently using C#

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.

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.

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.

Categories

Resources