Been trying to add a non secure endpoint to my self hosted service, so basically I have one interface that uses sessions and another one that doesn't. They are both implemented by the same class. Here's part of my server config file:
<service name="PT.DataServices.WCFService.PTDataServices" behaviorConfiguration="dataServiceBehavior">
<endpoint address="PTDataServices" binding="wsHttpBinding" contract="PT.DataServices.WCFService.IPTDataServices" bindingConfiguration="wsHttpBinding1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="PTDataServicesNoSessions" binding="wsHttpBinding" contract="PT.DataServices.WCFService.IPTDataServicesNoSessions" bindingConfiguration="wsHttpBinding2">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://*/PT6/DataServices/"/>
</baseAddresses>
</host>
</service>
Interface without sessions:
[ServiceContract(
SessionMode = SessionMode.NotAllowed
)]
public interface IPTDataServicesNoSessions
{
[OperationContract]
string GetData(int value);
}
Interface with sessions:
[ServiceContract(
SessionMode=SessionMode.Required
)]
public interface IPTDataServices
{
[OperationContract(IsInitiating = true, IsTerminating = false)]
DcUser InitSession(string userCode, string passwordEncrypted, string connectionString);
[OperationContract(IsInitiating = false, IsTerminating = true)]
int EndSession();
[OperationContract(IsInitiating = false, IsTerminating = false)]
string GetData(int value);
}
Putting :http://localhost/PT6/DataServices/ in a browser returns :
The PT.DataServices.WCFService.IPTDataServicesNoSessions.GetData operation references a message element [http://tempuri.org/:GetData] that has already been exported from the PT.DataServices.WCFService.IPTDataServices.GetData operation.
I don't want to change all clients to use different method names depending on the endpoint that is dynamically being used... how can I tell WCF that it's OK to have the same methods on each of the 2 interfaces?
Figured it out myself. I needed to add the namespace attribute to my interfaces:
[ServiceContract(
SessionMode=SessionMode.Required,
Namespace = "PTDataServices/WithSession"
)]
and
[ServiceContract(
SessionMode = SessionMode.NotAllowed,
Namespace = "PTDataServices/NoSessions"
)]
This allowed for WCF to avoid method name collisions in the WSDL for the methods that have the same name in both interfaces.