/ / WCF typy chýb nie je možné zaregistrovať pri otvorenej službe - c #, .net, wcf, rest

Typy chýb WCF nie je možné zaregistrovať pri otvorenej službe - c #, .net, wcf, rest

V súčasnej dobe máme aplikáciu, ktorá má aserverová aplikácia, ktorá vystavuje službu WCF REST, a potom máme stranu klienta, ktorá komunikuje so službami WCF REST na serveri. Momentálne sa mi na strane klienta zobrazuje chyba, ktorú nedokážem zistiť, a nemám šťastie v hľadaní odpovedí Google.

Hneď ako zavolám zChannelFactory na vytvorenie kanála je vyvolaná nasledujúca výnimka. Vie niekto, čo znamená táto chyba a kde nájdem niečo, čo by mi pomohlo problém vyriešiť? Ďalej je uvedená všeobecná metóda, ktorú používame na volanie služby zo strany klienta. Fiddler neukazuje žiadnu komunikáciu vychádzajúcu z klienta, takže problém je priamo na strane klienta. Server aj klient zdieľajú rovnaké komunikačné rozhranie.

    System.InvalidOperationException was caught
HResult=-2146233079
Message=New types cannot be registered with serializer manager after the service has been opened.
Source=System.ServiceModel.Web
StackTrace:
at System.ServiceModel.Dispatcher.UnwrappedTypesXmlSerializerManager.RegisterType(Object key, IList`1 types)
at System.ServiceModel.Dispatcher.SingleBodyParameterXmlSerializerMessageFormatter..ctor(OperationDescription operation, Type parameterType, Boolean isRequestFormatter, XmlSerializerOperationBehavior xsob, UnwrappedTypesXmlSerializerManager serializerManager)
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.CreateXmlFormatter(OperationDescription operation, Type type, Boolean isRequestFormatter, UnwrappedTypesXmlSerializerManager xmlSerializerManager)
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.CreateClientFormatter(OperationDescription operation, Type type, Boolean isRequestFormatter, Boolean useJson, UnwrappedTypesXmlSerializerManager xmlSerializerManager)
at System.ServiceModel.Description.WebHttpBehavior.<>c__DisplayClass7.<>c__DisplayClassa.<GetRequestClientFormatter>b__4()
at System.ServiceModel.Description.WebHttpBehavior.<>c__DisplayClass7.<GetRequestClientFormatter>b__3()
at System.ServiceModel.Description.WebHttpBehavior.HideReplyMessage(OperationDescription operationDescription, Effect effect)
at System.ServiceModel.Description.WebHttpBehavior.GetRequestClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint)
at System.ServiceModel.Description.WebHttpBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
at System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)
at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
at System.ServiceModel.ChannelFactory.CreateFactory()
at System.ServiceModel.ChannelFactory.OnOpening()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at System.ServiceModel.ChannelFactory.EnsureOpened()
at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at Enterprise.ServiceModel.ChannelFactoryExtensions.ExecuteRequest[TChannel,TResult](ChannelFactory`1 factory, Func`2 readDelegate) in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkEnterprise.CommonServiceModelChannelFactoryExtensions.cs:line 115
at Foo.Service.Client.FooDataMessenger.RetrieveAircraft() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Service.ClientClientFooDataMessenger.cs:line 699
at Foo.Service.Client.FooDataMessenger.<ReadAircraft>b__3() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Service.ClientClientFooDataMessenger.cs:line 95
at Enterprise.DelegateHelpers.ElapsedFunc[TOut](Func`1 actionDelegate, TOut& result) in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkEnterprise.CommonExtensionsDelegateHelpers.cs:line 103
at Enterprise.DelegateHelpers.ElapsedFuncTrace[TOut](Func`1 actionDelegate, String location, String method, String action) in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkEnterprise.CommonExtensionsDelegateHelpers.cs:line 128
at Foo.Service.Client.FooDataMessenger.ReadAircraft() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Service.ClientClientFooDataMessenger.cs:line 91
at Foo.Service.FooServiceClientData.ReadAircraft() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Service.ClientFooServiceClientData.cs:line 215
at Foo.Config.Data.InternalDatumController.get_Aircraft() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Config.DataInternalDatumController.cs:line 90
at Foo.Config.Data.Sync.AircraftDefsSyncView.ReadData() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Config.DataSyncFooDataAircraftDefsSyncView.cs:line 81
at Foo.Synchronization.Databases.Base.SyncProvider.ReadViewData(String viewName, Int32 batchCount) in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.SynchronizationDatabasesBaseSyncProvider.cs:line 88
at Foo.Synchronization.Databases.Base.SyncOrchestrator.Synchronize() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.SynchronizationDatabasesBaseSyncOrchestrator.cs:line 114
at Foo.Synchronization.Plugin.Synchronizer.Synchronize_FooData() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Synchronization.PluginSynchronizer.cs:line 201
at Foo.Synchronization.Plugin.Synchronizer.Sync() in C:UsersUser 1DesktopFoo_TFSFoo 5.1TrunkFoo.Synchronization.PluginSynchronizer.cs:line 91
InnerException:

Všeobecná metóda

public static TResult ExecuteRequest<TChannel, TResult>(
this ChannelFactory<TChannel> factory,
Func<TChannel, TResult> readDelegate)
{
if (factory == null || readDelegate == null)
{
return default(TResult);
}

TChannel channel = factory.CreateChannel();
#if DEBUG
// Changes the timeout to 10 minutes so you can step through server
// code if you need to without getting a timeout error.
((IClientChannel)channel).OperationTimeout = TimeSpan.FromMinutes(10);
#endif
TResult result;
try
{
result = readDelegate(channel);
}
finally
{
var client = (IClientChannel)channel;
if (client.State == CommunicationState.Faulted)
{
client.Abort();
}
else
{
client.Close();
}

client.DisposeSafe();
}

return result;
}

odpovede:

1 pre odpoveď č. 1

Riešenie problému spočíva v generikeMetóda zverejnená. Z nejakého dôvodu preto, že vo vyhlásení try / konečne sa vykonáva iba delegát, ktorý sa nakoniec nikdy nevykonával. Oprava tejto metódy je presunúť koniec do vnútra pokusu pomocou delegátskeho kódu a kanál nakoniec zlikvidovať. Ďalej uvádzame opravenú všeobecnú metódu.

public static TResult ExecuteRequest<TChannel, TResult>(
this ChannelFactory<TChannel> factory,
Func<TChannel, TResult> readDelegate)
{
if (factory == null || readDelegate == null)
{
return default(TResult);
}

TChannel channel = factory.CreateChannel();
#if DEBUG
// Changes the timeout to 10 minutes so you can step through server
// code if you need to without getting a timeout error.
((IClientChannel)channel).OperationTimeout = TimeSpan.FromMinutes(10);
#endif
TResult result;
try
{
result = readDelegate(channel);
var client = (IClientChannel)channel;
CommunicationState state = client.State;
if (state != CommunicationState.Faulted)
{
client.Close();
}
else
{
client.Abort();
}
}
catch (Exception)
{
((IClientChannel)channel).Abort();
throw;
}
finally
{
((IClientChannel)channel).DisposeSafe();
}

return result;
}