Application_BeginRequest doesn't fire In Web Service - asp.net

I created a web service on localhost, and I tried to call it from a web app (also on the localhost) via HttpWebRequest, but Application_BeginRequest in Global.asax didn't fire. When I type in IE 'http://localhost:8010/Test/' (the web service) Application_BeginRequest fires. Where is the problem? How can I test a localhost web service from a page which is also on localhost?

Generally, the best way to test a web service is to write a client to consume it. In particular, you can use a unit test framework to write automated tests of the service.
WCF doesn't even offer the web pages that allow you to test a service, BTW.

Not sure if you have a WCF web service or not, but if you do check out, "WCF Services and ASP.NET". WCF services aren't handled by IIS in the same way as web sites are, which may be the reason BeginRequest doesn't get hit:
The ASP.NET HTTP runtime handles ASP.NET requests but does not participate in the processing of requests destined for WCF services, even though these services are hosted in the same AppDomain as is the ASP.NET content. Instead, the WCF Service Model intercepts messages addressed to WCF services and routes them through the WCF transport/channel stack.

Related

Can IIS hosted WCF services perform background tasks?

I know that probably this question would be asked to many times but...
The wcf services hosted on iis7 in an asp. Net Web site can do things automatically? Like post a message to a pre-configured wall on Facebook given the permission to the application in a pre scheduled time?
For this to happen a client must send a request or it can do it alone?
The lifetime of a WCF service is typically determined by requests from a client i.e. if there is no client making requests then there is no service running.
Possible solutions:
Create a custom WCF ServiceHost, override the OnStart OnStop methods and create a background task.
Create an ASP.NET background task (external to WCF), which you can do with a library such as WebBackgrounder
Use the Windows Task Scheduler to trigger a task which polls your WCF service periodically which can then post outstanding messages to Facebook.

Calling WCF service from host

I am hosting a WCF service library in an ASP.net web application, which also needs to consume it. What is the best way to do so? Should I create a client proxy and invoke the service that way or is there a way of directly calling it? (the library is a project reference after all, and I guess doing so would be faster)
Since your WCF service library is a project reference for your web application, you could just instantiate the service directly without creating a client proxy. This approach would indeed be faster since you wouldn't be going through the serialization and deserialization that WCF does. However, you may wish to create a client proxy and access the service that way. This approach would be useful if there's any chance you may at some point host the service outside of your web application. If you were to end up moving the service, you would just need to update the endpoint address in your web application's web.config file.

WCF service singleton with callback and hosted on IIS?

I have a WCF service hosted at IIS7 web application. It's created by a WebServiceHostFactory. The client connects to a service calls the Collect method, and data are stored to DB. All working fine.
Now I would like to refresh page every time the new data are "collected" (i.e. the service method Collect is called).
My question is: What is the best approach ?
I was considering the CallbackContract, but this would require a singleton pattern (service is now PerCall), or is it a wrong assumption ? Is this approach possible ?
My logic is:
ASP.NET page subscribes to WCF service
the service singleton is created from now on
when method is called the services calls subscribers (clients)
there should be therefore only one service instance in order to subscription to work (or is it ?)
the client page refreshes itself
regards,
Kate
You can't refresh the page in a user's browser from the sever. Browsers use HTTP, which is a request-response protocol, so if the browser hasn't issued a request, it won't be looking for a response from your server.
If you have a Silverlight application hosted in a browser, that's a different story, but you didn't mention Silverlight anywhere. You would also be able to do what you're asking using WebSockets in HTML5, but that's not fully standardized yet.

Calling web services from ASP.NET application and connection management

I have an ASP.NET application that calls other web services through SSL (outside the application). I simply added a web reference (https://url/some.asmx) and used the web services and it works well. However, my questions are, how is the connection (channel) managed? is the connection to web services dropped after each web services call? or do they use the same connection (channel) for the subsequent calls? if they do, how long is the trusted connection kept alive?
Classic ASMX web services maintain the connection for a single request - that's why the methods you call via the web service class must be static. A SOAP call is very similar to a plain vanilla HTTP Request:
Open connection to URL
Pass in request - get/post, etc
Server renders an XML (SOAP) response
Connection is closed
Client processes response.
The web service framework wraps most of this so that you can conveniently access the web service as if it were a local object, but there is no server-side object instance persistence any more than there is for an ASPX page.
WCF services, on the other hand, maintain the connection until the proxy object is closed. This gives you a LOT of power, but, of course, with great power comes great responsibility.
update: link regarding ssl caching:
http://social.msdn.microsoft.com/forums/en-US/asmxandxml/thread/f86066e0-a24b-4d5e-873c-ed427d1faef7/

Silverlight and ASP.NET authorization

My website uses Forms authentication. I did silverlight 3 module which is designed to work in context of asp - authenticated user. Silverlight module talks with WCF hosted by the same asp.net website, but the issue is that it cannot authenticate to WCF service.
I run Fiddler and I see that .ASPXAUTH cookie is not sent to WCF service.
How to force Silverlight to get this cookie from browser and send it to service?
Finally I solved it.
The problem of missing cookie was made by inproper host name.
I was sending asp.net requests to myhostname, but SL was calling WCF using myhostname.mylocaldomainnam.local. This is why there was no .aspauth cookie during WCF calls.
I've used it successfully. First, I make sure that there are is a service endpoint for the WCF AuthorizationService used by ASP.NET. Then use the Silverlight project to generate a "Service Reference" to the AuthorizationService. Finally, in your module, you will use that service reference to login your visitor using their credentials stored within your provider. If you have some more information on how you've built your site, I might be able to offer a more concise answer to your problem.

Resources