如何在 WCF 端点的 XML 配置中指定合约的命名空间?
我有这个 WCF 服务合同(大大简化,但要注意它所在的命名空间):
namespace Foo.Services.BarService
{
[ServiceContract]
interface BarContract {... }
}
在我的 app.config
(客户端)中,我为某些服务配置了一个端点:
<endpoint address="..."
binding="..."
contract="Foo.Services.BarService.BarContract" />
但是,这个导致错误,指出在支持 BarService.BarContract
的客户端配置中找不到端点。我只能通过将 contract
属性值更改为 BarService.BarContract
(即通过删除命名空间)来消除此错误。
这是为什么?这个错误可能来自哪里?为什么我不能提及契约类型的命名空间部分?这是否会导致 WCF 找不到匹配的端点?
回复下面@Ladislav Mrnka评论中的问题:
我说的是客户端。 (我忘了提及这一点;对此感到抱歉。) 这个错误可能来自服务器端吗?
我通过 Visual Studio 的添加服务引用工具生成了上述服务协定以及实现它的
BarClient
类。我指定了由其他人运行的BarService
的 URL。我还指定该服务应放置在Foo.Services.BarService
命名空间中。- 打算直接通过为我自动生成的
BarClient
类使用该服务,而不是通过ChannelFactory
。
I've got this WCF service contract (heavily simplified, but pay attention to the namespace it's in):
namespace Foo.Services.BarService
{
[ServiceContract]
interface BarContract {... }
}
In my app.config
(client side), I configure an endpoint for some service:
<endpoint address="..."
binding="..."
contract="Foo.Services.BarService.BarContract" />
However, this results in an error saying that no endpoint was found in the client's configuration that supports BarService.BarContract
. I can only get rid of this error by changing the contract
attribute value to BarService.BarContract
(i.e. by removing the namespace).
Why is that? Where could this error come from? Why must I not mention the namespace part of a contract type? Shouldn't that result even more in WCF not finding a matching endpoint?
Reply to the questions in @Ladislav Mrnka's comment below:
I am talking about the client side. (I forgot to mention this bit; sorry for that.)
Can this error possibly come from the server side?I generated the above service contract, along with a
BarClient
class that implements it, via Visual Studio's Add Service Reference facility. I specified the URL of theBarService
, which is run by someone else. That's where I also specified that the service should be put in theFoo.Services.BarService
namespace.I was going to use the service directly via the
BarClient
class auto-generated for me, not via aChannelFactory<BarContract>
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过添加服务引用创建客户端不会从服务重新创建命名空间结构。所有创建的类型和契约都被放置到由服务引用的名称定义的新命名空间中。所以我猜你将你的服务引用命名为 BarService。客户端配置必须遵循生成的合约名称。
Creating client by Add Service reference does not recreate namespace structure from service. All created types and contracts are placed into new namespace defined by the name of the service reference. So I guess you named your service reference BarService. Client configuration must follow names of generated contracts.