J'ai créé deux services de repos WCF1 et service2 hébergés dans des ports distincts et utilisé Castle Windsor pour l'injection de dépendances dans service1 et maintenant à partir de service1 essayant d'appeler service2. mais quand je crée une instance et appelle pour le service2 j'obtiens une exception disant la mauvaise demande (400). Lorsque je demande un service2 à partir du client REST, je peux obtenir la réponse 200. est l'erreur due au comportement de château Windsor style de vie? ci-dessous est le code utilisé pour appeler le service 2.Est-il possible d'injecter WCF REST client via castle windsor
config Container (Service 1)
Container.AddFacility<WcfFacility>().Register(
Component.For(type).AsWcfClient(
new DefaultClientModel {
Endpoint = WcfEndpoint.FromConfiguration("*") }));
Configuration (Service 1)
<system.serviceModel>
<client>
<endpoint address="http://localhost:8082/BLDBService" binding="webHttpBinding" bindingConfiguration="customHttpBinding" contract ="DataSourceContracts.IBLDBService" behaviorConfiguration ="serviceEndpointHttpBehavior">
</endpoint>
</client>
<services>
<service name="BusinessService.MetaDataService" behaviorConfiguration="basicHttpBehavior">
<host>
<baseAddresses >
<add baseAddress ="http://localhost:8084/"/>
</baseAddresses>
</host>
<endpoint address="MetaDataService" binding="webHttpBinding" contract ="BusinessServiceContracts.IMetaDataService" behaviorConfiguration="endpointHttpBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<!--<basicHttpsBinding>
<binding name="BasicHttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpsBinding>-->
<webHttpBinding>
<binding name ="customHttpBinding" transferMode ="Streamed">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="endpointHttpBehavior">
<webHttp helpEnabled ="true" automaticFormatSelectionEnabled ="true" defaultOutgoingResponseFormat ="Json"></webHttp>
</behavior>
<behavior name="serviceEndpointHttpBehavior">
<webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled ="true" helpEnabled ="true" />
<dataContractSerializer/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="basicHttpBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
des appels de service (service 1)
_bldbService = Container.resolve<IBLDBService>();
WebOperationContext.Current.OutgoingRequest.ContentType = "application/json";
viewModel = _bldbService.GetBLDBData(viewModel);
Configuration (Service2)
<service name="BusinessService.BLDBService" behaviorConfiguration="basicHttpBehavior">
<!--<endpoint address="net.tcp://localhost:8082/BLDBService" binding="netTcpBinding" contract="BusinessServiceContracts.IBLDBService"/>-->
<host>
<baseAddresses>
<add baseAddress ="http://localhost:8082/"/>
</baseAddresses>
</host>
<endpoint address="BLDBService" binding="webHttpBinding" contract ="BusinessServiceContracts.IBLDBService" behaviorConfiguration="endpointHttpBehavior"/>
</service>
En appelant du client REST
post-scriptum J'ai testé avec le protocole net/tcp et cela fonctionne parfaitement.
est ici le journal
Time : 06.03.2017 11:11:15
----------------------------------------------------------------------------------------------------------------
Message : The remote server returned an unexpected response: (400) Bad Request.
----------------------------------------------------------------------------------------------------------------
Environment : Castle.Facilities.WcfIntegration
----------------------------------------------------------------------------------------------------------------
Stack Trace : at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.InvokeRealProxy(RealProxy realProxy, WcfInvocation wcfInvocation)
at Castle.Facilities.WcfIntegration.WcfInvocation.Proceed()
at Castle.Facilities.WcfIntegration.RepairChannelPolicy.Apply(WcfInvocation wcfInvocation)
at Castle.Facilities.WcfIntegration.Proxy.WcfRemotingInterceptor.PerformInvocation(IInvocation invocation, Action`1 action)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IBLDBServiceProxy.GetBLDBData(MetaDataViewModel viewModel)
at BusinessLogic.BLDBBusinessManager.GetData(MetaDataViewModel viewModel) in C:\localPTC\Sample\BasicFramework\BusinessLogic\BLDB\BLDBBusinessManager.cs:line 46
at BusinessService.MetaDataService.GetMetaData(MetaDataViewModel metadata) in C:\localPTC\Sample\BasicFramework\BusinessService\Services\MetaDataService.cs:line 16
----------------------------------------------------------------------------------------------------------------
Time : 06.03.2017 11:11:15
----------------------------------------------------------------------------------------------------------------
Message : The remote server returned an error: (400) Bad Request.
----------------------------------------------------------------------------------------------------------------
Environment : System
----------------------------------------------------------------------------------------------------------------
Stack Trace : at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
----------------------------------------------------------------------------------------------------------------
Le code que vous partagiez est d'appeler "Service2" de "Service1"? Avez-vous configuré les paramètres et le conteneur pour "Service2" également? Pouvez-vous partager cette configuration aussi? Avez-vous essayé de déboguer et vérifier si elle a atteint le code "Service2" du tout? –
@ chetan-ranpariya Si j'appelle du client REST il atteindra et donnera 200 réponse mais je quand appelez par l'intermédiaire du château windsor instance instance dire sa mauvaise demande qui signifie la demande aller au serveur mais le type de demande est invalide. –
Obtenez-vous d'autres informations lorsque vous recevez une réponse «Demande incorrecte» du service, telle que des informations d'erreur, une erreur de validation des données, une autorisation échouée, etc.? Aussi quand votre débogage "Service1" frappe-t-il la ligne 'viewModel = _bldbService.GetBLDBData (viewModel);' dans "Service1"? –