Reputation: 8428
I'm new to WCF; as of now my WCF project references a DLL library which contains a lot of public classes.
I created a .net 4.0 WCF project with a simple interface class and an .SVC file which implements the interface. I don't see any part of the app.config or anything else which I could use to restrict the shared objects.
How can I restrict the WCF service so that only certain public classes can get consumed by the WCF client? Or can this not be done?
I'm trying to expose some functions + classes via a WCF service for some clients to use, but the classes are stored within this DLL. I don't want to share all the classes within the dll but only a subset.
I know this is going to sound dumb... but somehow the issue went away. I'm not sure if a restart did it or what not, but i'm not having any of those issues anymore.
But I did learn a bit about WCF; some article somewhere highlighted that a good practice is to go beyond the interface and .SVC design and actually to use different assemblies to follow separation of concerns pattern.
Upvotes: 1
Views: 648
Reputation: 4662
Short answer to your question is
1) You either control what you expose through your endpoints
2) You put further restrictions inside your service method implementation using Authorisation (What operations logged in user perform)
Long answer is read this article from MSDN it explains your question and lots of similar questions eg
Can any client call the service or do you want to control who can call the service?
Can any client call any method of the service or do you want to control what clients can call what methods?
Can any client execute all of the code in a method or do you want to control what clients can execute what code?
Update: from your update
You need to separate your contracts in a dll and then share that dll with client and service. client is not going to have access to your implementation but just the contracts.
Upvotes: 1
Reputation: 28530
Say you have a DLL, that has a couple dozen methods, and you only want to expose 6 of them.
You develop a WCF service that has the six methods, and the implementation of the service references the DLL.
In your service implementation, you might have something like this:
public class MyService : IService
{
MyDll myDll = new MyDll();
public void Method1()
{
myDll.Method1();
}
public string Method2(int someValue)
{
return myDll.Method2(someValue);
}
// and so on
}
The interface (IMyService) might look something like this:
[ServiceContract]
public interface IMyService
{
[OperationContract]
void Method1();
[OperationContract]
string Method2(int someValue);
// and so on
}
The basic idea is that the WCF service acts as a wrapper around the underlying DLL, and only exposes those methods/classes that are specified in the interface.
When you generate the proxy via SvcUtil, you'll only see what is specified in the service, not everything in the underlying DLL - in fact, you shouldn't see anything from the underlying DLL because it's wrapped by the service.
Upvotes: 0