I have a class implementing a service contract. Another class being derived from this class and in turn implements another service contract
Class A: a.IA
{
}
Class B: A, b.IB
{
}
How do I expose the endpoints fo开发者_运维技巧r contract IB?
The endpoints I tried:
<service name="B">
<endpoint address="ep1" binding="webHttpBinding" contract="a.A1" />
<endpoint address="ep2" binding="webHttpBinding" contract="b.B1" />
</service>
If I do this, it gives error
Service 'B' implements multiple ServiceContract types, and no endpoints are defined in the configuration file. WebServiceHost can set up default endpoints, but only if the service implements only a single ServiceContract. Either change the service to only implement a single ServiceContract, or else define endpoints for the service explicitly in the configuration file.
Thanks in advance.
EDIT
the config had a typo above.
<service name="B">
<endpoint address="ep1" binding="webHttpBinding" contract="a.IA" />
<endpoint address="ep2" binding="webHttpBinding" contract="b.IB" />
</service>
The template I am using for this is WCF Rest template 4.0 (if it makes any difference)
The service class that implements the service is B
- and you use that correctly, as far as I can tell.
The contract that this service class implements is IB
- but that doesn't really show up in your config.
Try this:
<service name="B">
<endpoint address="ep1" binding="webHttpBinding" contract="a.IA" />
<endpoint address="ep2" binding="webHttpBinding" contract="b.IB" />
</service>
The contract in the endpoint must denote a service interface (typically) that defines the services method - that interface must have the [ServiceContract]
attribute applied to it.
OK - so that was a typo and your contracts are correct - but my question is then: are the a.
and b.
prefixes on the contracts the namespaces those contracts live in?
And if yes: why isn't the service tag using that namespace, too?? Does it make any difference if you change it to name="b.B"
:
<service name="b.B">
<endpoint address="ep1" binding="webHttpBinding" contract="a.IA" />
<endpoint address="ep2" binding="webHttpBinding" contract="b.IB" />
</service>
精彩评论