实现服务契约的类 另一个类 WCF 的基类
我有一堂课实施服务合同。另一个类从该类派生,并依次实现另一个服务契约
Class A: a.IA
{
}
Class B: A, b.IB
{
}
如何公开契约 IB 的端点?
我尝试过的端点:
<service name="B">
<endpoint address="ep1" binding="webHttpBinding" contract="a.A1" />
<endpoint address="ep2" binding="webHttpBinding" contract="b.B1" />
</service>
如果我这样做,它会给出错误
服务“B”实现了多个 ServiceContract 类型,并且没有 端点在配置文件中定义。 WebServiceHost 可以 设置默认端点,但前提是服务仅实现 单一服务合同。要么将服务更改为仅实现 单个 ServiceContract,或者定义服务的端点 明确地在配置文件中。
提前致谢。
编辑
上面的配置有一个拼写错误。
<service name="B">
<endpoint address="ep1" binding="webHttpBinding" contract="a.IA" />
<endpoint address="ep2" binding="webHttpBinding" contract="b.IB" />
</service>
我为此使用的模板是 WCF Rest 模板 4.0(如果有任何区别)
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 for 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现该服务的服务类是
B
- 据我所知,您使用它是正确的。该服务类实现的契约是 IB - 但这并没有真正显示在您的配置中。
试试这个:
端点中的契约必须表示定义服务方法的服务接口(通常) - 该接口必须具有
[ServiceContract]
应用于它的属性。好的 - 所以这是一个拼写错误,你的合同是正确的 - 但我的问题是:合同上的
a.
和b.
前缀是这些合同所在的命名空间?如果是的话:为什么服务标签也不使用该命名空间?如果将其更改为
name="bB"
会有什么区别吗: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:
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.
andb.
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"
: