Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过ServiceProxy访问无状态服务失败+;ASP.NET 5 Web API项目引发运行状况错误_C#_Asp.net_.net_Microservices_Azure Service Fabric - Fatal编程技术网

C# 通过ServiceProxy访问无状态服务失败+;ASP.NET 5 Web API项目引发运行状况错误

C# 通过ServiceProxy访问无状态服务失败+;ASP.NET 5 Web API项目引发运行状况错误,c#,asp.net,.net,microservices,azure-service-fabric,C#,Asp.net,.net,Microservices,Azure Service Fabric,我是microsoft azure服务结构的新手。为了获得硕士学位,我必须在ServiceFabric中开发一个微服务方法原型。经过数小时的研究,我仍然没有解决我的问题 我想在web前端(如中)访问我的(在部署的本地结构集群中)无状态服务。最简单的方法是将ASP.NET 5 Web Api项目添加到Service Fabric应用程序,并在ValuesController中调用ServiceProxy方法。因此,我在解决方案中添加了以下代码: ValuesController.cs: [路由(“

我是microsoft azure服务结构的新手。为了获得硕士学位,我必须在ServiceFabric中开发一个微服务方法原型。经过数小时的研究,我仍然没有解决我的问题

我想在web前端(如中)访问我的(在部署的本地结构集群中)无状态服务。最简单的方法是将ASP.NET 5 Web Api项目添加到Service Fabric应用程序,并在
ValuesController
中调用
ServiceProxy
方法。因此,我在解决方案中添加了以下代码:

ValuesController.cs:

[路由(“api/[控制器]”)]
公共类值控制器:控制器
{
//获取api/值/IObject
[HttpGet(“{interfaceName}”)]
公共异步任务获取(字符串接口名)
{
var serviceName=“fabric:/dataservicecfabric/MasterDataMService”;
var masterDataService=ServiceProxy.Create(新Uri(serviceName));
var result=await masterDataService.GetMasterDataByName(interfaceName);
返回结果。内容;
}
}
F5部署后,我的浏览器不会自动导航到我的web前端。通过查看Service Fabric Explorer,我的ASP.NET 5应用程序抛出运行状况错误:

Kind        Health State  Description
=============================================================================
Partitions  Error         Unhealthy partitions: 100% (1/1), MaxPercentUnhealthyPartitionsPerService=0%.
Partition   Error         Unhealthy partition: PartitionId='413...', AggregatedHealthState='Error'.
Event       Error         Error event: SourceId='System.FM', Property='State'. Partition is below target replica or instance count.
在这个问题之后,“分区低于目标副本或实例计数”表示我的服务中有一个未处理的异常正在阻止它启动。但我无法在我的服务结构资源管理器中找到堆栈策略来调试此故障。这是我的ASP.NET web服务的
ServiceManifest.xml

ServiceManifest.xml(Web1):


approot\runtimes\dnx-clr-win-x64.1.0.0-rc1-update1\bin\dnx.exe
--appbase approot\src\Web1 Microsoft.Dnx.ApplicationHost Microsoft.ServiceFabric.AspNet.Hosting--服务器Microsoft.AspNet.server.WebListener
代码包
这里是我的服务结构解决方案的
ApplicationManifest.xml

ApplicationManifest.xml:


因此,我使用ASP.NET 5 web应用程序和相同的
ValuesController.cs
创建了一个新的解决方案。我确保我的无状态服务在本地集群上运行,然后启动了新的web应用程序。在我的控制器中调用GET方法后,出现以下异常:

Exception thrown: 'System.Fabric.FabricException' in mscorlib.dll
Microsoft.AspNet.Hosting.Internal.HostingEngine: Information: Request finished in 0,2593ms 500
Microsoft.AspNet.Server.Kestrel: Error: An unhandled exception was thrown by the application.
System.Fabric.FabricException: Invalid partition key/ID '{0}'  for selector {1}
我的无状态服务是一个SingletonPartition,所以我需要一个分区键吗?如果是的话,我怎么才能拿到钥匙?服务结构资源管理器没有为我的无状态服务提供此信息。以下是我的无状态服务的
servicemifest.xml

ServiceManifest.xml(MasterDataMService):


MasterDataMService.exe
之后,我决定与OWIN建立服务通信:

MasterDataMService.cs:

内部密封类MasterDataMService:无状态服务,IMasterDataMService
{
[...]      
受保护的重写IEnumerable CreateServiceInstanceListeners()
{
返回新的[]
{
新的ServiceInstanceListener(initParams=>new-OWInCommunicationsListener(“MasterDataMService”,new StartUp(),initParams))
};
}
}
现在,我可以在我的
DefaultController
中使用
HttpClient
访问我的微服务:

var-client=new-HttpClient();
var请求=”http://localhost:80/MasterDataMService/api/values/query";
var result=string.Empty;
HttpResponseMessage response=wait client.GetAsync(请求);
if(响应。IsSuccessStatusCode)
{
结果=wait response.Content.ReadAsStringAsync();
}
但这不是我最初想要的。我不想在请求中指定服务端点。相反,我希望通过
ServiceProxy
与我的无状态服务通信。我如何在这里做到这一点?我做错了什么?如何使用部署到我的服务结构集群中的ASP.NET5应用程序解决此运行状况错误

谢谢你抽出时间

编辑:

无效分区密钥异常的扩展堆栈跟踪:

Exception thrown: 'System.Fabric.FabricException' in mscorlib.dll
Microsoft.AspNet.Hosting.Internal.HostingEngine: Information: Request finished in 0,2593ms 500
Microsoft.AspNet.Server.Kestrel: Error: An unhandled exception was thrown by the application.
System.Fabric.FabricException: Invalid partition key/ID '{0}'  for selector {1}
在mscorlib.dll中引发异常:“System.Fabric.FabricException”
Microsoft.AspNet.Hosting.Internal.HostingEngine:信息:请求在1,35ms 500内完成
Microsoft.AspNet.Server.WebListener.MessagePump:错误:ProcessRequestAsync
System.Fabric.FabriceException:选择器{1}->System.Runtime.InteropServices.COMException的分区键/ID“{0}”无效:HRESULT的异常:0x80071BBF
位于System.Fabric.Interop.NativeClient.IFabricServiceManagementClient4.EndResolveServicePartition(IFabricAsyncOperationContext上下文)
位于System.Fabric.FabricClient.ServiceManagementClient.ResolveServicePartitionEndWrapper(IFabricAsyncOperationContext上下文)
在System.Fabric.Interop.AsyncCallOutAdapter2`1.Finish(IFabricAsyncOperationContext上下文,布尔值expectedCompletedSynchronously)
---内部异常堆栈跟踪的结束---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在Microsoft.ServiceFabric.Services.Client.ServicePartitionResolver.d_u2a.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
在系统中运行
Exception thrown: 'System.ArgumentException' in mscorlib.dll
Microsoft.AspNet.Hosting.Internal.HostingEngine: Information: Request finished in 1,45ms 500
Microsoft.AspNet.Server.WebListener.MessagePump: Error: ProcessRequestAsync
System.ArgumentException: the provided uri scheme 'http' is invalid; expected 'net.tcp'.
Parametername: via
   at System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via)
   at System.ServiceModel.Channels.ConnectionOrientedTransportChannelFactory`1.OnCreateChannel(EndpointAddress address, Uri via)
   at System.ServiceModel.Channels.ChannelFactoryBase`1.InternalCreateChannel(EndpointAddress address, Uri via)
   at System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOverDuplexSession.CreateInnerChannelBinder(EndpointAddress to, Uri via)
   at System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress address, Uri via)
   at System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(Type channelType, EndpointAddress address, Uri via)
   at System.ServiceModel.DuplexChannelFactory`1.CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
   at System.ServiceModel.DuplexChannelFactory`1.CreateChannel(InstanceContext callbackInstance, Binding binding, EndpointAddress endpointAddress)
   at Microsoft.ServiceFabric.Services.Communication.Wcf.Client.WcfCommunicationClientFactory`1.<CreateClientAsync>d__2.MoveNext()
--- End of stack trace from the previous location where the exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientFactoryBase`1.<CreateClientWithRetriesAsync>d__1e.MoveNext()
System.ArgumentException: the provided uri scheme 'http' is invalid; expected 'net.tcp'.
System.Fabric.FabricException: Invalid partition key/ID '{0}'  for selector {1}
var proxyLocation = new ServiceUriBuilder("MasterDataMService");
var masterDataService = ServiceProxy.Create<IMasterDataMService>(proxyLocation.ToUri());

var result = await masterDataService.GetMasterDataByName(interfaceName);
    protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        return new[] { new ServiceInstanceListener(context => new FabricTransportServiceRemotingListener(context, this)) };
    }
System.Fabric.FabricException: Invalid partition key/ID '{0}'  for selector {1}
ServiceProxy.Create<IMasterDataMService>(0, new Uri("fabric:/DataServiceFabric/MasterDataMService"));
ServiceProxy.Create<IMasterDataMService>(new Uri("fabric:/DataServiceFabric/MasterDataMService"));
IHelloService service = ServiceProxy.Create<IHelloService>(new Uri("fabric:/Application1/HelloService"), new ServicePartitionKey(1));
  protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return new[] { new ServiceReplicaListener(context => this.CreateServiceRemotingListener(context)) };}
        ServiceProxy.Create<IMasterDataMService>(new Uri("fabric:/DataServiceFabric/MasterDataMService"), new ServicePartitionKey(0));