Calling WCF service from host - asp.net

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.

Related

Consul.IO - How to watch key/value data and announce to ASP.NET Web application to know these changes

Currently, I use Consul for storing App Settings and Configurations for ASP.NET Web application. But I got performance issue when every request need to query from Consul service.
I see Consul have watch feature in server but I did not know how to use it in Windows and how to announce Web Application know when key/value data change
As far as I know, watches allow you to invoke some handlers, which must be some executables. So you have to provide some API in your web-app to allow remotely call to reload configuration, for example, some kind of REST web service or something else, what can be called from outside.
Next you have to create some executable script on your agent's host and provide a logic to call this remote API of your web-app.
And finally you have to register a new watch, providing your script file as an executable.

How do I configure an ASP.net web application to invoke a WCF service host factory for named pipe calls?

I am hosting a WCF service in an ASP.net application. The service has two endpoints, an HTTP endpoint and a named pipe endpoint. I'm trying to consume the service from within the same web application using the named pipe endpoint.
The problem is that the service host factory isn't invoked until something tries to access the HTTP endpoint, so if the web application tries to call the service using the named pipe endpoint the call fails.
How do I configure the web application (or IIS) to invoke the service host factory for named pipe calls?
Update: My original premise was wrong. I took Petar's advice and installed AppFabric. This allowed me to see that the named pipe endpoint did in fact exist and that the service host factory had been invoked during an earlier build. I was able to test this by performing a clean build and setting a break point in the factory class.
Windows Server AppFabric could be your solution as it offers ability to manage service instance differently then with IIS and WAS. You can see here the screen where you can configure your services to auto start.
Beside this feature there are some other useful aspects of AppFabric you can read from the links above.

Call web services ONLY from client side

I have a web based application that uses lot of client side requests in various .asmx files.
I am wondering if I can use those web services only from client side and restrict the requests from other sources.
The reason for this is because I want to use those web services only from the current application and to restrict requests from other sources. For security reasons I could use soap authentication but since I requested the services from client side, I don't think the authentication it matters.
I'll appreciate any comments.
Thanks
The webservices are by definition public, publicly visible and available (unless they run on private network or standalone computer). I.e. anybody can access them. So, just deploying a webservice and hoping for the best is not a good approach.
And how do you intend to restrict other access?

.NET Java SOAP service change to WCF soap service

I currently have soap web services in java. Due to some architectural changes we need to move the services to WCF.
If the signatures are the same, can the string URI be changed and the .NET proxy will continue to work without any changes to the code?
If the contract (WSDL) remains absolutely the same then you only need to change address to the new server hosting the service - that is the theory. Now you need to build the WCF service which will really have the same contract. That can be hard task. I would start with generating interfaces from existing WSDL describing Java service (use svcutil for that).

Constrain the consumption of a web service to certain apps

Is there a way I can configure my asp.net web service to work with only some applications? In other words, I am saying "only these applications have access to this web service and can therefore use it. Others can't".
When other applications tries to discover the service, it shouldn't even show up, or at least it should conceal it web methods.
PS: I am wondering if this scenario is even applicable to the whole concept/domain of web services? Plus, I am asp.net 2.0 oriented, but you can give me answers based on higher framework versions, but be specific...Thanx in advance.
I'd look at WCF (after all ASMX web services are now regarded as legacy)- there is a whole load of options regarding security configuration. Patterns and Practises have Security Guidance here. It sounds like you are most interested in authorization, so read about Access Control Mechanisms.
Also to make the service non discoverable in WCF you just don't expose a MEX endpoint. That doesn't stop clients connecting, but makes it hard for people to work out how to call the service. That said you can also secure the MEX endpoints so that is another option.
Can you put some authorization or login method to initialize usage of webservice?
We control usage of services by explicitly logging into the webservice or provide some authorization token.

Resources