Close .asmx Web Service proxy class instance - c#

I have few questions lined up regarding web service,
Why should we close web service proxy class instance?
how should we close web service proxy class instance for asmx web services?
As using statement itself call dispose method at end, What if close function throws exception from dispose method? - So using statement should be used with try catch for traditional asmx web service for better code clean up ?
Thankful if anybody got a chance to stop by and answer.

Related

Calling wcf service from another WCF service hangs the call

I have several services running. I can call everyone from a client application. I am trying to call into one service from another service (same application - they are hosted in an application for testing but can also run as a windows service).
The call I use to do this from the client is simply create the factory and CreateChannel and then open.
When I do this in a service trying to connect to another service I don't get an error it just hangs and eventually times out. I have no idea what is wrong.
I am using net.pipe://localhost/test as my endpoint and transport.
This was really stupid but (and) I will post the issue to help others that may run into this...
All of my service was running single threaded so when I called into another service it was blocking itself. I now start my threads on backgroundworker threads and the issue is gone.
Thanks

Does WCF service method have something equivalent to ASP.NET Application_EndRequest?

I want to Dispose of some objects that are created during a WCF service method, but I need to clean them up outside of the scope of the method that created them. When I'm working in ASP.NET, I normally call that code during the Application_EndRequest event.
If the answer is: there is no Application_EndRequest-like event in WCF, how should I go about cleaning up my objects?
You can implement IDisposable for your WCF service. If the service is configured PerSession or PerCall *context mode* dispose method will be called once the channel is closed and the service instance is dropped.

Calling WCF after bypassing web proxy

I want to call wcf service hosted outside my netwerk. When i call that wcf from my code i got proxy authentication error as i am calling from machine which is covered with firewall.
So how i can provide my firewall proxy id/password programmatically to call the wcf service.
Somehow i have mananged to download proxy classes from that outside server which can call the wcf service but when i call any function i get the same error.
I have tried calling that code but i got error.

How do you end an Application from a Web Method within a Web Service?

I'm trying to create a method within a web service that will terminate the application when called. The purpose of this is to end a game being played with a Windows form. Does anyone have any ideas?
Generally your web method is in a completely different process, hence you cannot directly terminate the process [of the caller]. You should communicate the need to terminate back to the caller either via an indicator in the response or via an Exception (as part of a FaultContract).
If the WinForm is running on the server, where the web service is, you can stop it using Process.Kill method
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx
I believe I can "stop" the web service by clearing the session variables. Is this true? Using code:
Session.Contents.Abandon();

WCF: What is a ServiceHost?

As I'm currently learning to use WCF Services, I am constantly encountering tutorials on the internet which mention using a ServiceHost when using a WCF Service.
What exactly is this ServiceHost ?
In my current project I am using a WCF Service and having a reference to it from my app and whenever I want to consume it from my app I just instantiate its ServiceClient like such:
new MusicRepo_DBAccess_ServiceClient(new InstanceContext(instanceContext), customBinding, endpointAddress);
And then access my web methods (OperationContracts) from that instance (obviously opening it before consuming the method and closing it afterwards with Open and Close)
My WCF service is host in my IIS and I just access the .svc from my app to instantiate the ServiceClient.
So why and where is ServiceHost used?
A ServiceHost basically provides you everything you need to host a WCF service in a non-IIS or WAS setting. A common place for a ServiceHost would be in a console app or Windows service. See the example code from MSDN for how to setup a ServiceHost in a console app.
Your service implementation is just a .NET class - you need to have a runtime environment for it, so it can be executed somehow. That's what the ServiceHost is for - it will load your service class, set up the endpoints and channel listeners and all that stuff, and thus give your service class an "ecosystem" to live and operate in.
You can either instantiate a ServiceHost class yourself in a console app, a Windows service, or even a Winforms app, and thus make your WCF service class available to the outside world - or you can delegate that work to IIS or WAS. Even IIS or WAS will use a ServiceHost to host your WCF service - they just do it automagically behind the scenes, and "on demand" - whenever a request for your WCF service comes in.
Marc

Categories