Usuário com melhor resposta
Problemas com Silverlight e FaultExceptions.

Pergunta
-
Pessoal,
Estou tentando fazer com que o Silverlight 4 entenda o FaultExceptions, segui o respectivo link:
http://msdn.microsoft.com/en-us/library/dd470096%28VS.96%29.aspx .
Mas estou tendo problemas com a tag: <silverlightFaults/>, quando retiro a mesma consigo acessar o serviço perfeitamente, ao usar a mesma o seguinte erro é apresentado:
...
Parser Error Message: An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'silverlightFaults' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.
Parameter name: element
...
Segue abaixo o Web.config para uma melhor visualização:
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <customErrors mode="Off"/> </system.web> <system.serviceModel> <extensions> <behaviorExtensions> <add name="silverlightFaults" type="Servico.SilverlightFaultBehavior, Servico, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions> <services> <service name="Servico.Teste"> <endpoint address="" binding="basicHttpBinding" contract="Servico.Teste" bindingConfiguration="Servico.Teste.customBinding0"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <bindings> <basicHttpBinding> <binding name="Servico.Teste.customBinding0"> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name=""> <silverlightFaults/> // TAG QUE GERA O PROBLEMA APRESENTADO ACIMA. </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> </configuration>
Como resolver tal situação, De forma ao Silverlight conseguir ententer o FaultException ?Desde Já, Agradeço.
segunda-feira, 31 de outubro de 2011 19:05
Respostas
-
Bom dia Rodrigo,
aparentemente o Silverlight não consegui identificar sua extensão. Note que no código abaixo você faz referência ao objeto Servico.SilverlightFaultBehavior:
<extensions> <behaviorExtensions> <add name="silverlightFaults" type="Servico.SilverlightFaultBehavior, Servico, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions>
Verifique se esta classe implementa as interfaces que deveria, e se está acessível para a página em que está tentando utilizá-la.Abraços,
Daniel Cheida de Oliveira- Editado Daniel Cheida sexta-feira, 4 de novembro de 2011 16:08
- Marcado como Resposta _dev terça-feira, 8 de novembro de 2011 13:34
terça-feira, 1 de novembro de 2011 09:39 -
O problema foi resolvido, muito obrigado a todos que derão atenção ao respectivo post, segue abaixo o Web.config corrigido, isso pode ajudar alguem que esteja com o mesmo problema:
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <customErrors mode="Off"/> </system.web> <system.serviceModel> <extensions> <behaviorExtensions> <add name="silverlightFaults" type="Servico.SilverlightFaultBehavior, Servico, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions> <services> <service name="Servico.Teste"> <endpoint address="" binding="customBinding" contract="Servico.Teste" behaviorConfiguration="SilverlightFaultBehavior" bindingConfiguration="Servico.Teste.customBinding0" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <bindings> <customBinding> <binding name="Servico.Teste.customBinding0"> <textMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="SilverlightFaultBehavior"> <silverlightFaults/> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> </configuration>
- Marcado como Resposta _dev terça-feira, 8 de novembro de 2011 13:33
terça-feira, 8 de novembro de 2011 13:32
Todas as Respostas
-
Bom dia Rodrigo,
aparentemente o Silverlight não consegui identificar sua extensão. Note que no código abaixo você faz referência ao objeto Servico.SilverlightFaultBehavior:
<extensions> <behaviorExtensions> <add name="silverlightFaults" type="Servico.SilverlightFaultBehavior, Servico, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions>
Verifique se esta classe implementa as interfaces que deveria, e se está acessível para a página em que está tentando utilizá-la.Abraços,
Daniel Cheida de Oliveira- Editado Daniel Cheida sexta-feira, 4 de novembro de 2011 16:08
- Marcado como Resposta _dev terça-feira, 8 de novembro de 2011 13:34
terça-feira, 1 de novembro de 2011 09:39 -
Prezado Daniel Cheida,
Inicialmente gostaria de agradecer pela atenção, possuo um ASP.NET Empty Web Application denominado Servico e dentro do mesmo possuo a classe SilverlightFaultBehavior, no qual postei o código abaixo para uma melhor visualização:
using System; using System.Collections.Generic; using System.Web; using System.ServiceModel.Description; using System.ServiceModel.Configuration; using System.ServiceModel.Dispatcher; using System.ServiceModel.Channels; using System.ServiceModel; namespace Servico { // http://msdn.microsoft.com/en-us/library/dd470096%28VS.96%29.aspx public class SilverlightFaultBehavior : BehaviorExtensionElement IEndpointBehavior { public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { SilverlightFaultMessageInspector inspector = new SilverlightFaultMessageInspector(); endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector); } public class SilverlightFaultMessageInspector : IDispatchMessageInspector { public void BeforeSendReply(ref Message reply, object correlationState) { if (reply.IsFault) { HttpResponseMessageProperty property = new HttpResponseMessageProperty(); // Here the response code is changed to 200. property.StatusCode = System.Net.HttpStatusCode.OK; reply.Properties[HttpResponseMessageProperty.Name] = property; } } public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { // Do nothing to the incoming message. return null; } } // The following methods are stubs and not relevant. public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { } public void Validate(ServiceEndpoint endpoint) { } public override System.Type BehaviorType { get { return typeof(SilverlightFaultBehavior); } } protected override object CreateBehavior() { return new SilverlightFaultBehavior(); } } }
Se você observar todos os modificadores de acesso são public e a respectiva classe implementa as seguintes interfaces: BehaviorExtensionElement, IEndpointBehavior.Novamente Obrigado.
Grande Abraço.
terça-feira, 1 de novembro de 2011 12:29 -
O problema foi resolvido, muito obrigado a todos que derão atenção ao respectivo post, segue abaixo o Web.config corrigido, isso pode ajudar alguem que esteja com o mesmo problema:
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <customErrors mode="Off"/> </system.web> <system.serviceModel> <extensions> <behaviorExtensions> <add name="silverlightFaults" type="Servico.SilverlightFaultBehavior, Servico, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions> <services> <service name="Servico.Teste"> <endpoint address="" binding="customBinding" contract="Servico.Teste" behaviorConfiguration="SilverlightFaultBehavior" bindingConfiguration="Servico.Teste.customBinding0" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <bindings> <customBinding> <binding name="Servico.Teste.customBinding0"> <textMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="SilverlightFaultBehavior"> <silverlightFaults/> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> </configuration>
- Marcado como Resposta _dev terça-feira, 8 de novembro de 2011 13:33
terça-feira, 8 de novembro de 2011 13:32