WCF 与多个端点的通信
WCF-Communication with multiple endpoints
我有问题。我尝试构建具有多个实体的 WCF 通信。但它永远不会工作,它会显示这样的错误消息:
- 在服务“{1}”实施的合同列表中找不到合同名称“{0}”。
这是我的配置文件:
*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="MwWcfLibrary.Service">
<endpoint address="net.tcp://localhost:8733"
binding="netTcpBinding"
bindingConfiguration=""
bindingName="Action"
name="ActionInterface"
contract="MwWcfLibrary.Actions.Interfaces.IAction">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
bindingConfiguration=""
name="Mex"
contract="IMetadataExchange" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="LifeSignInterface"
bindingName="LifeSign"
contract="MwWcfLibrary.LifeSign.Interfaces.ILifeSign" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="DataInterface"
bindingName="Data"
contract="MwWcfLibrary.Notification.Interfaces.IData">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="PublicDataInterface"
bindingName="PublicData"
contract="MwWcfLibrary.PublicData.Interfaces.IPublicData" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="PublicStateInterface"
bindingName="PublicState"
contract="MwWcfLibrary.PublicState.Interfaces.IPublicState" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8733//MwWcfLibrary" />
</baseAddresses>
<timeouts closeTimeout="00:00:30" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
*
有人知道我是不是配置有误吗?
亲切的问候。
编辑
您可能还没有实现以下接口之一:
MwWcfLibrary.Actions.Interfaces.IAction
、MwWcfLibrary.LifeSign.Interfaces.ILifeSign
、MwWcfLibrary.PublicData.Interfaces.IPublicData
和 MwWcfLibrary.PublicState.Interfaces.IPublicState
或其中一个或多个未使用 [ServiceContract]
属性修饰
在您的问题中包含实际错误而不是“{0}”,您会看到您的某些合同尚未由 class Service
实施,应该如下所示(至少):
class Service : IAction, ILifeSign, IPublicData, IPublicState
{
// implementation
}
此外,您的地址属性似乎不正确,因为您定义了一个以段结尾的基地址 //Mww... 但在您的端点中,该地址比基地址短。端点地址可以是相对的,如 "Service"
.
以前
Service
元素指的是 class,它是 ServiceContract
接口的实现,是 endpoint
契约属性中的内容。验证接口的完全限定名称和这些属性中的 classes。
从您的配置文件来看,您是说 class MwWcfLibrary.Service
实现了名为 MwWcfLibrary.Actions.Interfaces.IAction
、MwWcfLibrary.LifeSign.Interfaces.ILifeSign
的([ServiceContract]
修饰的)接口, MwWcfLibrary.PublicData.Interfaces.IPublicData
和 MwWcfLibrary.PublicState.Interfaces.IPublicState
这似乎是错误的。您的意思是要有两个服务,每个服务都有一个单独的端点?
我有问题。我尝试构建具有多个实体的 WCF 通信。但它永远不会工作,它会显示这样的错误消息:
- 在服务“{1}”实施的合同列表中找不到合同名称“{0}”。
这是我的配置文件:
*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="MwWcfLibrary.Service">
<endpoint address="net.tcp://localhost:8733"
binding="netTcpBinding"
bindingConfiguration=""
bindingName="Action"
name="ActionInterface"
contract="MwWcfLibrary.Actions.Interfaces.IAction">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
bindingConfiguration=""
name="Mex"
contract="IMetadataExchange" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="LifeSignInterface"
bindingName="LifeSign"
contract="MwWcfLibrary.LifeSign.Interfaces.ILifeSign" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="DataInterface"
bindingName="Data"
contract="MwWcfLibrary.Notification.Interfaces.IData">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="PublicDataInterface"
bindingName="PublicData"
contract="MwWcfLibrary.PublicData.Interfaces.IPublicData" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint binding="netTcpBinding"
address="net.tcp://localhost:8733"
bindingConfiguration=""
name="PublicStateInterface"
bindingName="PublicState"
contract="MwWcfLibrary.PublicState.Interfaces.IPublicState" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8733//MwWcfLibrary" />
</baseAddresses>
<timeouts closeTimeout="00:00:30" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
*
有人知道我是不是配置有误吗?
亲切的问候。
编辑
您可能还没有实现以下接口之一:
MwWcfLibrary.Actions.Interfaces.IAction
、MwWcfLibrary.LifeSign.Interfaces.ILifeSign
、MwWcfLibrary.PublicData.Interfaces.IPublicData
和 MwWcfLibrary.PublicState.Interfaces.IPublicState
或其中一个或多个未使用 [ServiceContract]
属性修饰
在您的问题中包含实际错误而不是“{0}”,您会看到您的某些合同尚未由 class Service
实施,应该如下所示(至少):
class Service : IAction, ILifeSign, IPublicData, IPublicState
{
// implementation
}
此外,您的地址属性似乎不正确,因为您定义了一个以段结尾的基地址 //Mww... 但在您的端点中,该地址比基地址短。端点地址可以是相对的,如 "Service"
.
以前
Service
元素指的是 class,它是 ServiceContract
接口的实现,是 endpoint
契约属性中的内容。验证接口的完全限定名称和这些属性中的 classes。
从您的配置文件来看,您是说 class MwWcfLibrary.Service
实现了名为 MwWcfLibrary.Actions.Interfaces.IAction
、MwWcfLibrary.LifeSign.Interfaces.ILifeSign
的([ServiceContract]
修饰的)接口, MwWcfLibrary.PublicData.Interfaces.IPublicData
和 MwWcfLibrary.PublicState.Interfaces.IPublicState
这似乎是错误的。您的意思是要有两个服务,每个服务都有一个单独的端点?