Can I have a single service with multiple endpoints and multiple contracts using generics. I am running into an issue where the metadata cannot be created (It hink it may just be a config issue and not sure what my base host address would need to look like):
namespace WCFSingleService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface ISingleService<T>
{
[OperationContract]
T GetData(T item);
}
}
namespace WCFSingleService
{
[ServiceContract(Name = "User")]
public interface IUserSingleService: ISingleService<User>
{
}
}
namespace WCFSingleService
{
[ServiceContract(Name = "Some")]
public interface ISomeSingleService: ISingleService<Some>
{
}
}
public partial class SingleService : IUserSingleService
{
public User GetData(User item)
{
//Do something
}
}
public partial class SingleService : ISomeSingleService
{
public Some GetData(Some item)
{
//Do something
}
}
Is this possible and what would the configuration for this service look like? Also, would I be able to consume the service from, say, an AJAX client? I guess I would since I am not trying to pass in a type to the contract and each contract would have its own endpoint, right? Thanks!
Here is my current configuration:
<system.serviceModel>
<services>
<service name="WCFSingleService.SingleService" behaviorConfiguration="WCFSingleService.ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/WCFSingleService/SingleService" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="User" binding="wsHttpBinding" contract="WCFSingleService.IUserSingleService"/>
<endpoint address="Some" binding="wsHttpBinding" contract="WCFSingleService.ISomeSingleService"/>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFSingleService.ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
UPDATE:
Well, I was tring to figure out why my servcie wasn;t wroking, once I turned debugging on, that opened up the error dorr. DUH! Anyway, the issue I was having had to do with the same method name being created for both services. So, does anyone know of a way to have WCF rename the method names if multiple services impelement the same interface? Is there a decoration I can put on a method inside one of the implementations to make it appear different?
I figured out pretty much what I wanted to accomplish. Basically, I could still setup my code to use generics while having one service. I got the idea for the single service here. I then realized that I needed to specify the ServiceContract on the partial class SingleService (Not the interfaces themselves) and decorate my implemented methods with the OperationContract(Name=”TheExposedNameOfTheMethod”). Here is some of the code:
Here is what the endpoint would look like: