2017-09-05 77 views
0

我創造了Azure的服務織物上API的應用程序,我面臨着以下問題:System.Runtime.InteropServices.COMException在使用服務織物

例外:

System.Runtime.InteropServices.COMException occurred 
    ErrorCode=-2146233628 
    HResult=-2146233628 
    Message=Field of ByRef type. (Exception from HRESULT: 0x801312E4) 
    Source=mscorlib 
    StackTrace: 
     at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type) 
     at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() 
     at System.Reflection.Emit.TypeBuilder.CreateTypeInfo() 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.MethodBodyTypesBuilder.BuildRequestBodyType(ICodeBuilderNames codeBuilderNames, CodeBuilderContext context, MethodDescription methodDescription) 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.MethodBodyTypesBuilder.Build(ICodeBuilderNames codeBuilderNames, CodeBuilderContext context, MethodDescription methodDescription) 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.MethodBodyTypesBuilder.Build(InterfaceDescription interfaceDescription) 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.CodeBuilder.Microsoft.ServiceFabric.Services.Remoting.Builder.ICodeBuilder.GetOrBuildMethodBodyTypes(Type interfaceType) 
     at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyGeneratorBuilder`2.Build(Type proxyInterfaceType, IEnumerable`1 interfaceDescriptions) 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.CodeBuilder.Microsoft.ServiceFabric.Services.Remoting.Builder.ICodeBuilder.GetOrBuildProxyGenerator(Type interfaceType) 
     at Microsoft.ServiceFabric.Services.Remoting.Builder.ServiceCodeBuilder.GetOrCreateProxyGenerator(Type serviceInterfaceType) 
     at Microsoft.ServiceFabric.Services.Remoting.Client.ServiceProxyFactory.CreateServiceProxy[TServiceInterface](Uri serviceUri, ServicePartitionKey partitionKey, TargetReplicaSelector targetReplicaSelector, String listenerName) 
     at Microsoft.ServiceFabric.Services.Remoting.Client.ServiceProxy.Create[TServiceInterface](Uri serviceUri, ServicePartitionKey partitionKey, TargetReplicaSelector targetReplicaSelector, String listenerName) 
     at WebService.Controllers.HomeController.<GetAsync>d__0.MoveNext() in C:\Users\shkulka\Documents\Visual Studio 2015\Projects\SortingApp\WebService\Controllers\HomeController.cs:line 17 
    InnerException: 

線在哪個異常發生:

IRequestManagerService proxy = ServiceProxy.Create<IRequestManagerService>(new Uri("fabric:/SortingApp/RequestManagerService")); 

參考某些代碼

http://localhost:8792/api/home?opId=0&sortType=Quick&guid=12&commaSeperatedArray=1,2,3,4 

我正在我的項目具有管理員權限:當我打下面的網址發生210

例外。整個解決方案中的平臺目標是x64。

如何擺脫異常?


更新1:

之前我打的網址,我可以觀察以下有關服務織物。

在服務織物探險:

enter image description here

在診斷活動窗口:

enter image description here


0:

{ 
    "Timestamp": "2017-09-06T10:49:34.7442479+05:30", 
    "ProviderName": "Microsoft-ServiceFabric-Services", 
    "Id": 2, 
    "Message": "RunAsync has been cancelled for a stateful service replica. The cancellation will be considered 'slow' if RunAsync does not halt execution within 4000 milliseconds. Application Type Name: GettingStartedApplicationType, Application Name: fabric:/GettingStartedApplication, Service Type Name: MyActorServiceType, Service Name: fabric:/GettingStartedApplication/MyActorService, Partition Id: 097c837b-857e-4f10-8c3a-8a902c1f0bb6, Replica Id: 131491461074099453", 
    "ProcessId": 34840, 
    "Level": "Informational", 
    "Keywords": "0x0000F00000000000", 
    "EventName": "StatefulRunAsyncCancellation", 
    "ActivityID": null, 
    "RelatedActivityID": null, 
    "Payload": { 
    "applicationTypeName": "GettingStartedApplicationType", 
    "applicationName": "fabric:/GettingStartedApplication", 
    "serviceTypeName": "MyActorServiceType", 
    "serviceName": "fabric:/GettingStartedApplication/MyActorService", 
    "partitionId": "097c837b-857e-4f10-8c3a-8a902c1f0bb6", 
    "replicaId": 131491461074099453, 
    "slowCancellationTimeMillis": 4000.0 
    } 
} 

{ 
    "Timestamp": "2017-09-06T10:49:34.760793+05:30", 
    "ProviderName": "Microsoft-ServiceFabric-Services", 
    "Id": 2, 
    "Message": "RunAsync has been cancelled for a stateful service replica. The cancellation will be considered 'slow' if RunAsync does not halt execution within 4000 milliseconds. Application Type Name: GettingStartedApplicationType, Application Name: fabric:/GettingStartedApplication, Service Type Name: MyActorServiceType, Service Name: fabric:/GettingStartedApplication/MyActorService, Partition Id: 78f9a969-4f09-4d8b-932f-4962cce7f4cd, Replica Id: 131491461074094464", 
    "ProcessId": 27832, 
    "Level": "Informational", 
    "Keywords": "0x0000F00000000000", 
    "EventName": "StatefulRunAsyncCancellation", 
    "ActivityID": null, 
    "RelatedActivityID": null, 
    "Payload": { 
    "applicationTypeName": "GettingStartedApplicationType", 
    "applicationName": "fabric:/GettingStartedApplication", 
    "serviceTypeName": "MyActorServiceType", 
    "serviceName": "fabric:/GettingStartedApplication/MyActorService", 
    "partitionId": "78f9a969-4f09-4d8b-932f-4962cce7f4cd", 
    "replicaId": 131491461074094464, 
    "slowCancellationTimeMillis": 4000.0 
    } 
} 

打網址後

更新2:

接口:

namespace RequestManagerService.Interfaces 
{ 
    public interface IRequestManagerService : IService 
    { 
     Task submitSortRequest(string sortType, string guid, string commaSeperatedArray); 
     Task<bool> isSortingComplete(string guid); 
     Task<string> getSortedArray(string guid); 
     Task<bool> isSortRequested(string sortType, ref string commaSeperatedArray, ref string guid); 
     Task setSortResult(string sortType, string guid, string sortedArray); 
    } 
} 

接口實現:

namespace RequestManagerService 
{ 
    /// <summary> 
    /// An instance of this class is created for each service instance by the Service Fabric runtime. 
    /// </summary> 
    internal sealed class RequestManagerService : StatelessService, IRequestManagerService 
    { 
     // <guid,<sorttype, array, isSortComplete>> 
     Dictionary<string, Tuple<string, string, bool>> SortDictionary = new Dictionary<string, Tuple<string, string, bool>>(); 
     public RequestManagerService(StatelessServiceContext context) 
      : base(context) 
     { 

     } 

     public async Task<string> getSortedArray(string guid) 
     { 
      Tuple<string, string, bool> tempTuple; 
      string sortedArray= ""; 

      if (await isSortingComplete(guid)) 
      { 
       SortDictionary.TryGetValue(guid, out tempTuple); 
       sortedArray = tempTuple.Item2; 
      } 
      else 
      { 
       sortedArray = "Either there no request with this guid or the sorting is not yet complete."; 
      } 
      return sortedArray; 
     } 

     public Task<bool> isSortingComplete(string guid) 
     { 
      bool isSortComplete = false; 
      Tuple<string, string, bool> tempTuple; 

      if (SortDictionary.ContainsKey(guid)) { 
       SortDictionary.TryGetValue(guid, out tempTuple); 
       isSortComplete = tempTuple.Item3; 
      } 

      return Task.FromResult(isSortComplete); 
     } 

     public Task<bool> isSortRequested(string sortType, ref string commaSeperatedArray, ref string guid) 
     { 
      bool requestFound = false; 

      foreach(KeyValuePair<string, Tuple<string, string, bool>> entry in SortDictionary) 
      { 
       if (entry.Value.Item1 == sortType && entry.Value.Item3 == false) 
       { 
        commaSeperatedArray = entry.Value.Item2; 
        guid = entry.Key; 
        requestFound = true; 
        break; 
       } 
      } 

      return Task.FromResult(requestFound); 
     } 

     public Task setSortResult(string sortType, string guid, string sortedArray) 
     { 
      if (SortDictionary.ContainsKey(guid)) 
      { 
       Tuple<string, string, bool> updatedTuple = new Tuple<string, string, bool>(sortType, sortedArray, true); 
       SortDictionary[guid] = updatedTuple; 
      } 
      return Task.FromResult<object>(null); 
     } 

     public Task submitSortRequest(string sortType, string guid, string commaSeperatedArray) 
     { 
      Tuple<string, string, bool> tuple = new Tuple<string, string, bool>(sortType, commaSeperatedArray, false); 
      SortDictionary.Add(guid, tuple); 
      return Task.FromResult<object>(null); 
     } 

     /// <summary> 
     /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. 
     /// </summary> 
     /// <returns>A collection of listeners.</returns> 
     protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() 
     { 
      return new ServiceInstanceListener[1] { 
       new ServiceInstanceListener(this.CreateServiceRemotingListener) 
      }; 
     } 

     /// <summary> 
     /// This is the main entry point for your service instance. 
     /// </summary> 
     /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param> 
     protected override async Task RunAsync(CancellationToken cancellationToken) 
     { 
      // TODO: Replace the following sample code with your own logic 
      //  or remove this RunAsync override if it's not needed in your service. 

      long iterations = 0; 

      while (true) 
      { 
       cancellationToken.ThrowIfCancellationRequested(); 

       ServiceEventSource.Current.ServiceMessage(this.Context, "Working-{0}", ++iterations); 

       await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); 
      } 
     } 
    } 
} 
+0

您能否分享您嘗試訪問的服務的合同實施? –

+0

@KirylZ:嘿,剛剛添加了界面及其實現。如果你有任何想法,請讓我知道。 –

+0

我想說ref/out參數在這裏的合同中不受支持。擺脫他們,然後再試一次。 –

回答

0

我想說,裁判輸入/輸出參數未在合同支持在這裏。理想情況下,您的服務聯繫人不應該依賴特定於語言的工件。擺脫他們,事情應該正常工作。

+0

大,非常感謝!如果可能的話,將我指向某些資源,其中提及ref/out參數在合同中不受支持。我想讀更多。 –

+1

不客氣。我記得在SF文檔中唯一的參考資料是[https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-get-started](https://docs。 microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-get-started)。你會在那裏找到「Actor接口方法不能有out,ref或可選參數。」 –

+0

我知道在WCF中可以使用ref參數來定義契約,但返回類型必須是'void'。由於使用SF遠程監聽器,你的方法必須是任務返回的異步方法,這可能是阻止你使用ref參數的原因。 –