积极答复者
在一个服务内的多个ServiceContract如果绑定到不同的endpoint上?

问题
答案
-
具体实现代码就不贴了,太难挑了,请包涵……
运行后会在Program.cs文件的如下行报错:
ServiceHost host = new ServiceHost(typeof(News.WCFService.NewsService));
在服务“NewsService”实现的协定列表中找不到协定名称“News.WCFService.NewsService.INewsAdminService”。
这里可以肯定的一点是命名空间和类名都不会错,因为我是用WCF配置向导配置的,并在选择协定框中选取。
最好把源代码提交上,看你的错误,是指 News.WCFService.NewsService 这个类没有实现 News.WCFService.NewsService.INewsAdminService 接口.- 已标记为答案 Allen Chen - MSFTModerator 2009年10月23日 3:39
全部回复
-
看你的描述,应该是消息安全模式下的Username身份验证。
配置。
可以参考这个文章:WCF分布式安全开发实践(8):消息安全模式之用户名身份验证:Message_UserName_WSHttpBinding
基本你要定义连个终结点endpoint,一个是IAdmin,另外一个是ISelect。
<endpoint
address="AdmiService"
binding="wsHttpBinding"
bindingConfiguration="BindingConfigration"
contract="IAdmin">
</endpoint>启用安全:
<wsHttpBinding>
<binding name="BindingConfigration">
<security mode="Message">
<transport clientCredentialType="None"/>
<message clientCredentialType="UserName" negotiateServiceCredential="true" establishSecurityContext="true"/>
</security>
</binding>
</wsHttpBinding>
netTcpBinding不适用安全的话配置很简单。机制配置即可。
<endpoint
address="SelectService"
binding="netTcpBinding"
bindingConfiguration="BindingConfigration"
contract="ISelect">
</endpoint>
记得终结点地址要给出baseAddress,或者你全部给出。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum -
版主在cnblog上的专栏我已经都学习过了,很受教。谢谢……
换成了self-host,不过问题依然没有解决,索性把代码全贴上来,还请帮忙看看:
[app.config]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="News.WCFService.NewsService">
<clear />
<endpoint address="ws" binding="wsHttpBinding" contract="News.WCFService.NewsService.INewsSelectService"
listenUriMode="Explicit">
<identity>
<dns value="MyServerCer" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:8001/newsservice" binding="netTcpBinding"
contract="News.WCFService.NewsService.INewsAdminService" listenUriMode="Explicit">
<identity>
<dns value="MyServerCer" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
listenUriMode="Explicit">
<identity>
<dns value="MyServerCer" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/newsservice" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
[Program.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;namespace BlogServiceHost
{
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(News.WCFService.NewsService));host.Open();
Console.WriteLine("WCF服务正在下列终结点运行: ");
foreach (ServiceEndpoint se in host.Description.Endpoints)
{
Console.WriteLine(se.Address.ToString());
}Console.ReadLine();
host.Close();
}
}
} -
Hi,
不用这么客气,呵呵
从错误提示上看,应该还是和契约的配置有关系。
给你个调试的建议,你试一下。
1.保留一个终结点,启动一下服务,看看还有没类似的错误;
2.简化一下命名空间,再调试看看错误。
有问题我们再交流
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum -
Hi,
单独调试每个终结点都没错误,但是全部调试久出错。
那你一个一个的增加总结点,慢慢打开全部终结点。
看看在第几个终结点的时候出错。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum -
具体实现代码就不贴了,太难挑了,请包涵……
运行后会在Program.cs文件的如下行报错:
ServiceHost host = new ServiceHost(typeof(News.WCFService.NewsService));
在服务“NewsService”实现的协定列表中找不到协定名称“News.WCFService.NewsService.INewsAdminService”。
这里可以肯定的一点是命名空间和类名都不会错,因为我是用WCF配置向导配置的,并在选择协定框中选取。
最好把源代码提交上,看你的错误,是指 News.WCFService.NewsService 这个类没有实现 News.WCFService.NewsService.INewsAdminService 接口.- 已标记为答案 Allen Chen - MSFTModerator 2009年10月23日 3:39