Mercurial > silverbladetech
comparison SilverlightExampleApp/SilverlightExampleApp.Web/Services/SilverlightFaultBehavior.cs @ 49:502f5f365649
Initial load for Silverlight Example Application
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Tue, 17 Apr 2012 17:57:52 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
48:d617b54e1f47 | 49:502f5f365649 |
---|---|
1 // This is an auto-generated file to enable WCF faults to reach Silverlight clients. | |
2 | |
3 using System; | |
4 using System.Collections.Generic; | |
5 using System.Collections.ObjectModel; | |
6 using System.Linq; | |
7 using System.Runtime.Serialization; | |
8 using System.Net; | |
9 using System.ServiceModel; | |
10 using System.ServiceModel.Channels; | |
11 using System.ServiceModel.Description; | |
12 using System.ServiceModel.Dispatcher; | |
13 | |
14 namespace SilverlightExampleApp.Web.Services | |
15 { | |
16 public class SilverlightFaultBehavior : Attribute, IServiceBehavior | |
17 { | |
18 private class SilverlightFaultEndpointBehavior : IEndpointBehavior | |
19 { | |
20 public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) | |
21 { | |
22 } | |
23 | |
24 public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) | |
25 { | |
26 } | |
27 | |
28 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) | |
29 { | |
30 endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SilverlightFaultMessageInspector()); | |
31 } | |
32 | |
33 public void Validate(ServiceEndpoint endpoint) | |
34 { | |
35 } | |
36 | |
37 private class SilverlightFaultMessageInspector : IDispatchMessageInspector | |
38 { | |
39 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) | |
40 { | |
41 return null; | |
42 } | |
43 | |
44 public void BeforeSendReply(ref Message reply, object correlationState) | |
45 { | |
46 if ((reply != null) && reply.IsFault) | |
47 { | |
48 HttpResponseMessageProperty property = new HttpResponseMessageProperty(); | |
49 property.StatusCode = HttpStatusCode.OK; | |
50 reply.Properties[HttpResponseMessageProperty.Name] = property; | |
51 } | |
52 } | |
53 } | |
54 } | |
55 | |
56 public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) | |
57 { | |
58 } | |
59 | |
60 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) | |
61 { | |
62 foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints) | |
63 { | |
64 endpoint.Behaviors.Add(new SilverlightFaultEndpointBehavior()); | |
65 } | |
66 } | |
67 | |
68 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) | |
69 { | |
70 } | |
71 } | |
72 } |