Get/Set the account under which WCF service is hosted - wcf

I am hosting my WCF service in a console application. I need to know -
How can I find out under which account and its details this service is hosted?
How can I set the account under which the service must be hosted (this is possible in windows service, but how can this be done in a console application?)
Thanks!

The current user can be found using:
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
There is an interesting impersonation library on github and available via NuGet that should do the trick:
SimpleImpersonation

Related

Remote debug WCF services running under a custom IIS account

I want to remote debug an WCF service. The application pool that hosts the WCF service runs under an custom account. The custom account is a domain account.
In the 'Attach to Process' window in Visual Studio 2012 I have checked 'Show all processes from all users' but it only shows WCF services that are hosted under a built-in IIS account (like NETWORK SERVICE, etc.).
How can I remotely debug this service?
Assuming you've gone through this https://msdn.microsoft.com/en-us/library/y7f5zaaa.aspx, you may need to go through this https://msdn.microsoft.com/en-us/library/9y5b4b4f.aspx
HTH!
You are not seeing because it is not hosted in your application. You have to host the Remote WCF Service first. Add Service reference to add WCF to your app. Then right click WCFService.svc file to view WCF Service in browser to start the service. It will now be available to you and you can Attach the process.

Consuming WCF Restful Service hosted by IIS

I have successfully deployed my WCF restful web service to IIS 7. I have verified that my service is working when I call it from a browser in IE via a something like "https://myserver/mservice.svc/postuser/JohnSmith" . The method is a POST and I have verified that my IIS configuration allows for POSTS.
My issue is as follows. We are using a 3rd party Software as a Service application that allows for external web service calls. It allows you to configure the URL "https://myserver/mservice.svc/postuser/" and then you can choose a parameter. When I call the web service from the external application, a 404 error is registered in IIS.
I think there must be some difference between the way I call my webservice "https://myserver/mservice.svc/postuser/JohnSmith" and the way the SAAS application is calling my external web service. The web service is attempting to pass the username, but I cannot detect how it is constructing this.
Do I need to write a web enabled front end for my web service that is hosted in IIS that can handle XML? I'm assuming this is how the SAAS application is trying to pass the username onto my web service.
Thank you all in advance for your ideas and help.

Is IIS a requirement in order to use AppFabric Server functionality for WCF Services?

I'm about to build a set of WCF Services. Previously I have written service-library DLL's and self hosted. However this new environment requires services to be deployed to AppFabric. It's my experience with AppFabric that it requires a .svc file, which must be hosted in IIS.
If I want to use AppFabric for my WCF services (Cacheing, Monitoring, Relay etc.) do I HAVE to use IIS? Or are there other options available to me? If so, what are those available options?
As far i know, all App Fabric requires is service to be hosted on WAS. By not having IIS you wont be able to use the IIS UI but i guess there would be command line options for this.
please have a look into :App Fabric FAQ

How to start/stop windows service from a remote machine through WCF service?

I have created a WCF service which is deployed on my local machine. This service exposes one method which start/stop a windows service on my local machine.
On the remote machine I have created a client that consumes the WCF service. When I try to invoke the method which start/stop service exposed from a WCF service , I get InvalidOperationException . I found that this is the Security issue.
Also when I do the same operation (start/stop windows service) on the local machine it works!!
The WCF service is hosted on IIS 7.0 which is using basichttpBinding. Also Anonnymous access is checked. I have also added <identity Impersonate = true > under the web section in the web config file but still no success.
Please help!!
You set impersonation for ASP.NET. Impersonation in WCF uses its own infrastructure. Moreover in WCF client has to allow service to impersonate his identity. Check this simple example.

How would you communicate a wcf service with a windows service?

Two weeks ago I needed a way to communicate a wcf service with a windows service running on the same computer. The windows service had to get data from a external source and share it with the wcf service (hosted in IIS) who had to give it when a client made a request. I chose to do that with ipc.
I done it and now the windows service is the ipc server and the wcf service is the ipc client. This goes well but I think I made a mistake doing this because to make it run right the windows service must to be executed with the ASPNET account, for this the ASPNET password account must be assigned and when I do that the IIS does not work correctly.
I am thinking on different alternatives, but in all of them the problem persists. Some ideas?
Edit:
What I needed was a system that made public, in a web service hosted in IIS, data gotten through telnet from another old system, what is a little unstable. How the response of this second system was slow I chose to put a process (the windows service) between the web service and the old system. The windows service had to save the data collected from the old system and when the wcf service asked it give it all at once through ipc.
Why does the windows service need to run as the ASPNET user? Is that because you're using an IPC connection that requires authentication from the caller?
Another alternative (if you have control over the windows-service code) would be to make that a WCF service as well (using a ServiceHost in the windows service). The IIS service could connect to the windows service using a NetTcp or NetNamedPipe binding if you need the IPC-like performance.
Why not just create another account with the same permission set of the ASPNET user which both the WCF service and your other service run under? That way, you have control over the password.
Ideally, the windows service should run as a WCF service, that way its easy for the client to communicate with it.
The next question is weather the 'client' needs to be a WCF service. If this client needs to serve other applications then it is appropriate, otherwise it may not be nessesary. I don't know enough about your system, so its up to you to decide what's best!