Restrict the client connection in WCF service - wcf

I have created a WCF service and hosted it in console application. I have 2 client applications which will communicate with that WCF service, now I want to restrict 3 clients to connect to this WCF service.
Is there any way to reject the connection at server side for 3rd client?
Or is there any way server can validate the connection before establishing with
client?
Server side code
Uri httpBaseAddress = new Uri("net.pipe://localhost/ServiceHost/ServiceHost");
studentServiceHost.AddServiceEndpoint(typeof(StudentService.IStudentService), binding, httpBaseAddress);
studentServiceHost.Open()

If you want to stop 3 Clients from Connection to the service at the same time you can use the maxConnections attribute of the binding, setting it to 2.
If you only want specific Clients to Access Your service. Then you need to set up authentication, see: WCF self hosting require authentication

Related

Is there is a config setting for tracing WCF calls ?

I have simple wcf web service that i contain two endpoint connection
soap
rest
I want to have the ability to save the client request and the my server respond on each session as original xml/json.
How to do it ?

WCF Client default SPN generation

How does WCF client generates target Service's SPN dynamically to get the kerberos ticket in Spnego Use case?
For example, if the target service is running under domain machine account, SPN associated with the Service would be in the form 'host/machinename'.
If we try to call the service using wcf client, wcf client is able to get the ticket for host/machinename. I initially thought that wcf client might be using hardcoded string host/+domainname by default.
But If I change the target service to run under domain user and associate SPN named "http/machinename" with the domain user, wcf client is still able to generate the ticket for this service successfully.
How does WCF client decides whether to use prefix 'host/' or 'http/' in these scenarios.
I know that there is a way to add custom spn on the client side under endpoint element but I'm interested to know how it works by default.
The default is host/myhostname for Windows credential type. This is also the expected SPN while running the WCF service with a machine account.
Note that the WSDL will include the Identity (e.g. SPN), so the WCF client can use that information while connecting. Check the WCF Test Client Config file to see what is actually generated.

How to set credentials for proxy when connecting to WCF service

I have a program that is a WCF service which connects to third-party WCF service via a proxy server. What I need to specify in app.config to use custom user credentials to this proxy?

Silverlight, WCF service relay and security

I have a silverlight 4 application which needs to consumes some services hosted on a Java (I think CXF) Web Service.
For some reasons, I can't access directly the service so I have to go through a relay service.
I created a WCF relay service.
The service uses SOAP 1.2 and WS addressing 1.0
What I ask is.. what level of security can I reach?
The ideal situation is to use a mutual authentication of the server (CXF) and my client.
If Silverlight does not support this, the second possibility is to have a "simple" https connection between my silverlight client and my relay server, but then, is it possible to "add" a mutual authentication between the relay and CXF? Or the only possible solution is to have a simple SSL connection with only the server authentication?

WCF Callback Service hosted over basicHttpBinding and wsDualHttpBinding

I have a callback service that is hosted over wsDualHttpBinding. I'm looking to add a client that will poll for the data rather than receive the callback (will be a mobile device using wince for demo purposes). I was curious what the best way to do this is? You cannot create a client proxy using NetCFSvcUtil with a service hosted with wsDualHttpBinding (I understand that), but you cannot host a callback service over basicHttpBinding. I really need the same service hosted over both basicaHttpBinding (clients will poll for data) and wsDualHttpBinding (callback will notify clients of data). Any ideas on the best way to handle this without creating two separate services to host the same data?
What do you mean by two separate services hosting the same data? Do you expect to share same service instance to handle both wsDualHttpBinding and basicHttpBinding requests?
Your current problem is that service interface for duplex communication cannot be used for basicHttpBinding. You have to create second service contract and implement it in the same service. In that case you can expose two endpoints for the service: one duplex with WSDualHttpBinding and one with BasicHttpBinding. Endpoints must have different relative addresses. From the perspective of the client those endpoints are separate services - each of them requires separate client proxy. So unless your service is singleton you will have new service instance for each client proxy. New service instance means no data sharing.
Thera are some possibilities to modify this behavior but it means replacing Instance provider.