7
Answers

WCF Interface from another assembly

NeCroFire

NeCroFire

13y
5.6k
1
Hi

I'm still pretty new to WCF, so maybe this is a stupid question.

I have a WCF service and was wondering if it were possible to reference different DLL's with service contracts in them and make them accessible through the same service?

So I would have one dll with something like this in it:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  public partial class MyTestClass : IMyTestClass
  {
 
  public string _TestSalesOptions()
  {
  return "SalesOpstion says Halo!";
  }
  }

[ServiceContract]
  public interface IMyTestClass
  {
  [OperationContract]
  string _TestSalesOptions();
  }


Now... would I be able to reference this dll in my main service and add a endpoint??
I've spend the better part of the morning googling and I haven't found any results to what I'm trying to do. Maybe it can't be done? Maybe we should rather create separate small services?

 
Answers (7)
0
Praneeth Kumar

Praneeth Kumar

NA 832 43.4k 13y
Can you share the test project which you are working on. I can fix it and give it for you.
0
NeCroFire

NeCroFire

NA 86 0 13y
I can't get it to work. It keeps telling me that it can't find my contract. I'm thinking the service does not know to look for IMyTestClass in MyTest.dll. Can I tell it in what dll to look for the code?? If so how?
0
Praneeth Kumar

Praneeth Kumar

NA 832 43.4k 13y
It should work. Give it a try. Let me know if you are facing any issues.
0
NeCroFire

NeCroFire

NA 86 0 13y
What if I want to add more than one dll, but I make the namespace the same? I'm going to give it a try.
0
Praneeth Kumar

Praneeth Kumar

NA 832 43.4k 13y
You dont have to do that. You have to specify the proper namespace of the interfaces project in the endpoint like

 <endpoint address="" binding="basicHttpBinding"  name="BasicHttpBinding_IServiceName"   contract="<Interface Namespace>.InterfaceName">


Keynote is the projects namespace should be mentioned properly.

Even in the .svc file you need to mention proper namespace

<%@ ServiceHost Language="C#" Debug="true" Service="<NameSpace of service methods>.Name of service method class" CodeBehind="path of service method class file" %>
0
NeCroFire

NeCroFire

NA 86 0 13y
Can you elaborate a little more? What do I need to do in the config file? I'm assuming just adding an extra endpoint won't do it?
0
Praneeth Kumar

Praneeth Kumar

NA 832 43.4k 13y
It can be done. You can event put data contracts, operation contracts in separate project. You have to configure the web.config properly.