WCF Silverlight service returns a custom error, but since the HTTP 500 response is not 200

It seems that I forever hit my head with user errors in my Silverlight WCF service, so I would be happy to BUY BEER for those who can help me solve this problem !!

After severe pain, I finally got my WCF service, which throws custom errors ( ParameterValidationFault ) and uses Fiddler. I know that the service response contains my serial failure object, but the HTTP response code is 500, not 200, so the client launches instead of reading the response.

I know that my SilverlightFaultBehavior class should take care of changing the response status code, but the breakpoints I set there never get there, so I hope this is a simple problem with web.config (web.config at the end of the post).

If that matters, my web.config shows that the "element behavior" has an invalid child element "silverlightFaults" ... "in the section

  <endpointBehaviors> <behavior name="SilverlightFaultBehavior"> <silverlightFaults/> </behavior> </endpointBehaviors> 

but I thought this was not a problem as I can view the service metadata without errors. However, now I think this is a missing link that prevents the output status code from changing. I read that this error indicates a problem with the type attribute in my behaviorExtension element, which doesn’t exactly match what .NET thinks should be, but I checked it a million times, and the namespace and assembly name are definitely correct. I did not bother with a version, culture, or public key.

Is there an easy way for .NET to tell me what a type string is (spaces, commas and all)? I looked at the dll properties in explorer, but I'm still not closer.

Any other suggestions on where this might come from would be greatly appreciated.

 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <extensions> <behaviorExtensions> <add name="silverlightFaults" type="my.namespace.SilverlightFaultBehavior, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions> <behaviors> <endpointBehaviors> <behavior name="SilverlightFaultBehavior"> <silverlightFaults/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="my.namespace.IService.customBinding0"> <binaryMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <services> <service name="my.namespace.IService"> <endpoint address="" binding="customBinding" bindingConfiguration="my.namespace.IService.customBinding0" contract="my.namespace.IService" behaviorConfiguration="SilverlightFaultBehavior" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel> </configuration> 

My SilverlightFaultBehavior class starts this way and is a copy of this namespace-modified MSDN record

 namespace my.namespace { public class SilverlightFaultBehavior : BehaviorExtensionElement, IEndpointBehavior { public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { 
+4
source share
1 answer

OK, so this problem was not resolved, but was handled. I finally saw in this very useful post that I might have an anonymous endpointBehavior s. The behavior is now applied, and user errors correctly (in a non-standard form) are returned as HTTP 200s. The behavior of anonymous behavior means that it applies to all endpoints, but since my service currently requires only one endpoint, this works for me.

It really sucks that I had all this grief after reading the guide to frigin and its implementation verbatim. In the end, my parsing error "element behavior" has an invalid child element "silverlightFaults" ... ", it didn’t matter, but a very smelly red herring along the way, as that could very well be the reason (and still could be) .

In case someone wonders, I just drank beer.

0
source

All Articles