Call two web service methods simultaneously(parallel) - c#

I am new in .Net development..........
I want to call two web service methods simultaneously(parallel) using c# code from the application, web service is built as a separate application. In my application, one web service method should get called & it is not needed to wait for the response, then another service method should get called & it is not needed to wait for the response, but after calling both of these service methods, I need to wait for the respond for first method & as per the result I need to proceed ahead, what is the best way to perform this?

Related

How to call one logic app from other logic app which currently located in different subscription

I have a requirement to call the logic app from other logic app which is located in a different subscription. how can I call?
I know how to call one logic app from other logic app when both are in the same subscription. How can I call if it is in different subscription?
You can use the HTTP trigger 'When a HTTP request is received'. With this you can define a schema. After the logic app is deployed you a link will be generated with a token in the url. Just call this URL from your first logic app. The URL will contain api-version,sp,sv and a sig. Hope it helps to get you started.

How to know if a website is correctly working or not?

Have just completed developing a WebAPI.
Now, creating an client application for the same.
To do this, I had created a WPF Client application which needs the user to enter the parent URI of the service.
That is,
http://localhost:65620/VirtualDirectoryName (Just the base URL not the entire URL)
Now, how to check if the URL is correct or not using the client application?
EDIT 1:
HttpClient can be used: But I am asking about validating the base URL alone.
Any ideas how to do this ?
(If I put the base address in the Browser, it shows the contents of the Directory. Then I assume that the installation is correct (At this point I am not calling any methods of webAPI though))
EDIT 2:
URL is Correct or not: I have to ensure that the service has been installed correctly in the IIS and it is up and running before any client could access its methods.
So you have a WebAPI that cannot be modified, and a client application that cannot be modified. You need to call one of the API methods using something, to check the API has been deployed correctly.
Either use the client application to call one of the API's methods.
Or create a test application which calls one of the API's methods.
I may be missing something, but surely there must be a simple GET method in your API that you can call from your test application that would prove the API is running.

How to call windows service methods from web application

I need to develop windows service which will do fortnightly transfers of files into the system. The problem is that I will also need "RunNow" method, so users can call transfer method any time by clicking to the link in the web app (asp.net mvc).
How can I call my windows service methods from external resource?
If you want to call a windows service method on the server side of your web application then take a look at the WCF or RestSharp and Nancy. Shortly, you need to create a RESTfull service in the windows service application that will be using a http://localhost/myservice/transfer address to expose the Transfer method. Then use ajax from your javascript code or RestRequest from your .net-controller class to call the address.
But if you want to call a windows service method on the client side of the application it will be a problem.
You could use Microsoft Message Queuing
The Webapplication would send a Message that the Service picks up.
Queue-Based Background Processing in ASP.NET MVC Web Application
http://msdn.microsoft.com/en-us/library/ms978430.aspx

ASMX service sharing a single class instance

I have a webservice with a .asmx extension which points to a class in my web application. After adding some code to output a debug log on application startup, I can see a new debug log is being created every time a user visits the page.
I was hoping that I could configure this web service to only ever use a single instance.
Meaning, when the first user visits the site it creates an instance of my webservice, and then all requests after are routed through that same class, sharing the same state.
Is this even possible?
Web sites are stateless in nature. Meaning, each request is generally unrelated to any other request.
That said, you could set the log as a static variable in your global.asax file. Be aware of threading issues.
Alternatively you might look at Elmah.
You seem to have a number of problems.
First of all, the ASMX technology is all but obsolete, and should not be used for new development. WCF should be used instead.
Next, yes, you can have multiple calls to the service share the same instance of your class. However, you'll have to prevent simultaneous access to this class unless it is thread safe. You should expect multiple service calls to call into the same class instance at the same time.
Finally, ASMX does not support singleton web services. The best you can do is to have multiple service calls all share the same object (carefully locked).

C# How to initialize WebService

Is there a possibility to initialize a WebService.
I'm searching for a method that runs only during first call to WebService. Is there something like it in .Net ?
If you require "initialisation" the first time a given client connects to the Web Service:
Have an Initialise method that returns a token, such a a GUID, that's then required on every call made to the actual "does the work" method of your web service. You can then ensure that for that client the service is always initialised.
If you require it the first time the web service is ever called:
Add some code to your service, as a private method, that is called at the top of each public method. Within it check for the existance of something, such as a registry entry, file, database record or other persistant value. If it doesn't exist, perform your initialisation and then create the "something".
If you require it on the first call since IIS last recycled/started the Application Pool:
Have a static constructor for the class so that when it's first instantiated the static constructor runs and performs your initialisation.
If you are trying to initialize a resource that is used by the web service and you only want to initialize it once per application, you can use the Application_Start event on the Global.asax. Be aware that IIS will recycle the application pool whenever the application pool is eating up too many resources.
If you need to initialize class level variable, you can do it in the constructor of the web service. I would recommend against that, because your web service should be stateless. If you need to initialize a static resource once in your web service, you can use a static constructor.
If you need a single resource that is available once throughout your application, I would recommend you look into the singleton pattern.
When you create a WebService application in Visual Studio, by default a class named "Service" will be added. When you look at the code for this class (Service.cs), you'll see a constructor ("public Service()") with two commented-out lines. You can either put your initialization code here, or call a private method that you've defined inside the Service class. This constructor will be called only when your client makes its first call to any WebMethod in the Service class.
Well, there's no equivalent to the J2EE initialization if that's what you're after... However each web app is hosted in an application domain. Every now and then an application may be recycled and a new application domain may be created...
You can use Application_Start in global.asax, it will run once if any webservice inside your project is called

Categories