我已经使用无状态服务和Web API设置了基本的Service Fabric解决方案,并测试了使用默认服务远程处理侦听器的所有功能。快乐的时光!具有不同ContractDescriptions的服务结构多个ServiceEndpoints
当我尝试用服务总线中继替换默认侦听器时(我打算如何与服务进行通信),我在启动时收到错误。
CreateServiceInstanceListeners()
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] {
new ServiceInstanceListener(context => {
var wcfRelay = new WcfCommunicationListener<ICommercial>(
wcfServiceObject: this,
serviceContext: context,
endpointResourceName: "serviceRelay");
return wcfRelay;
})
};
}
服务配置(app.config)中
<system.serviceModel>
<extensions>…</extensions>
<services>
<service name="Commercial.Service.CommercialService">
<endpoint address="http://[namespace].servicebus.windows.net/CommercialService"
name="serviceRelay"
binding="basicHttpRelayBinding"
contract="Commercial.Interface.ICommercial"
behaviorConfiguration="relayToken" />
</service>
</services>
<bindings>
<basicHttpRelayBinding>
<binding closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" maxBufferSize="5886800" maxBufferPoolSize="524288" maxReceivedMessageSize="5886800" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="5886800" maxArrayLength="5886800" maxBytesPerRead="5886800" maxNameTableCharCount="16384" />
</binding>
</basicHttpRelayBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="relayToken">
<transportClientEndpointBehavior>
<tokenProvider>
<sharedAccessSignature keyName="RootManageSharedAccessKey" key="[key]" />
</tokenProvider>
</transportClientEndpointBehavior>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
如果我在听者创造打破我看到它的创建两个服务端点:
最终我得到这个错误,显示了Service Fabric Explorer中的每个节点。
不健康事件:SourceId ='System.RA',Property ='ReplicaOpenStatus',HealthState ='Warning',ConsiderWarningAsError = false。副本有多个失败in_Node_1 API调用:IStatelessServiceInstance.Open(); Error = System.InvalidOperationException(-2146233079)服务包含多个具有不同ContractDescriptions的ServiceEndpoint,每个具有Name ='ICommercial'和Namespace ='http://[schema_path]/20170713'。可以为ContractDescription提供唯一的名称和名称空间,或确保ServiceEndpoint具有相同的ContractDescription实例。 System.ServiceModel.Dispatcher.UniqueContractNameValidationBehavior.Validate(ServiceDescription description,ServiceHostBase serviceHostBase)at System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description,ServiceHostBase serviceHost)at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description,ServiceHostBase serviceHost )在System.ServiceModel.ServiceHostBase.InitializeRuntime()System.ServiceModel.ServiceHostBase.OnBeginOpen(TimeSpan超时,AsyncCallback回调,对象状态)在System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult.InvokeOpen()在System.ServiceModel.Channels。在Microsoft.ServiceFabric.Services.Communication System.ServiceModel.Channels.CommunicationObject.BeginOpen(TimeSpan超时,AsyncCallback回调,对象状态)CommunicationObject.OpenAsyncResult..ctor(CommunicationObject通信对象,TimeSpan超时,AsyncCallback回调,对象状态) 。Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.d__20.MoveNext()中的.Wcf.Runtime.WcfCommunicationListener`1.Microsoft.ServiceFabric.Services.Communication.Runtime.ICommunicationListener.OpenAsync(CancellationToken cancellationToken)之前引发异常的位置---在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.d__14.MoveNext( )
我不完全清楚如何解决此问题“要么为ContractDescriptions提供唯一的名称和名称空间,要么确保ServiceEndpoint具有相同的ContractDescription实例”。
我可以从创建的侦听器看到它正在创建在app.config中配置的侦听器。我想这个问题是为什么创建第二个默认的net.tcp监听器(请参阅主文章中的图片)。这就是错误产生的原因。 – ConfusedMonkey
@ConfusedMonkey在我的机器上复制了你的问题后,我会说你有两个端点的原因是这样的 - 第一个端点是从你的app.config文件创建的,第二个端点是由你的清单文件中的SF构建的,这就是您的服务将在SF命名服务中得到解决和了解的方式。所以我仍然建议看看我上面发布的文章,并在创建wcf监听器时在代码中完成所有必需的配置。 –
@ConfusedMonkey好像有一个帖子,显示了如何配置SF中的中继监听器 - [为服务总线中继绑定安装Azure服务结构监听器](https://stackoverflow.com/questions/43055785/setup-a -azure服务织物侦听换服务总线中继结合)。 –