CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Mobile/WcfPortal.cs
Go to the documentation of this file.
1#if !NETSTANDARD2_0 && !NET5_0
2//-----------------------------------------------------------------------
3// <copyright file="WcfPortal.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>Exposes server-side DataPortal functionality</summary>
8//-----------------------------------------------------------------------
9using System;
10using System.ServiceModel;
11using System.ServiceModel.Activation;
12using Csla.Core;
13using System.Security.Principal;
14using System.Threading.Tasks;
16
18{
23 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
24 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
25 public class WcfPortal : IWcfPortal
26 {
27
28#region IWcfPortal Members
29
34 [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
35 public async Task<WcfResponse> Create(CriteriaRequest request)
36 {
37 var result = new WcfResponse();
38 try
39 {
40 request = ConvertRequest(request);
41
42 // unpack criteria data into object
43 object criteria = GetCriteria(request.CriteriaData);
45 {
46 criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
47 }
48
49 var processor = new MobileRequestProcessor();
50 var createRequest = new MobileCriteriaRequest(
51 request.TypeName,
52 criteria,
53 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal),
54 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext),
55 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext),
56 request.ClientCulture,
57 request.ClientUICulture);
58
59 var createResponse = await processor.Create(createRequest).ConfigureAwait(false);
60 if (createResponse.Error != null)
61 {
62 result.ErrorData = new WcfErrorInfo(createResponse.Error);
63 }
64 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(createResponse.GlobalContext);
65 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(createResponse.Object);
66 }
67 catch (Exception ex)
68 {
69 result.ErrorData = new WcfErrorInfo(ex);
70 }
71 finally
72 {
74 }
75 return ConvertResponse(result);
76
77 }
78
83 [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
84 public async Task<WcfResponse> Fetch(CriteriaRequest request)
85 {
86 var result = new WcfResponse();
87 try
88 {
89 request = ConvertRequest(request);
90 // unpack criteria data into object
91 object criteria = GetCriteria(request.CriteriaData);
93 {
94 criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
95 }
96 var processor = new MobileRequestProcessor();
97 var fetchRequest = new MobileCriteriaRequest(
98 request.TypeName,
99 criteria,
100 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal),
101 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext),
102 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext),
103 request.ClientCulture,
104 request.ClientUICulture);
105
106 var fetchResponse = await processor.Fetch(fetchRequest).ConfigureAwait(false);
107 if (fetchResponse.Error != null)
108 {
109 result.ErrorData = new WcfErrorInfo(fetchResponse.Error);
110 }
111 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(fetchResponse.GlobalContext);
112 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(fetchResponse.Object);
113 }
114 catch (Exception ex)
115 {
116 result.ErrorData = new WcfErrorInfo(ex);
117 }
118 finally
119 {
121 }
122 return ConvertResponse(result);
123 }
124
129 [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
130 public async Task<WcfResponse> Update(UpdateRequest request)
131 {
132 var result = new WcfResponse();
133 try
134 {
135 request = ConvertRequest(request);
136 // unpack object
137 object obj = GetCriteria(request.ObjectData);
138
139 var processor = new MobileRequestProcessor();
140 var updateRequest = new MobileUpdateRequest(
141 obj,
142 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal),
143 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext),
144 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext),
145 request.ClientCulture,
146 request.ClientUICulture);
147
148 var updateResponse = await processor.Update(updateRequest).ConfigureAwait(false);
149 if (updateResponse.Error != null)
150 {
151 result.ErrorData = new WcfErrorInfo(updateResponse.Error);
152 }
153 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(updateResponse.GlobalContext);
154 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(updateResponse.Object);
155 }
156 catch (Exception ex)
157 {
158 result.ErrorData = new WcfErrorInfo(ex);
159 }
160 finally
161 {
163 }
164 return ConvertResponse(result);
165 }
166
171 [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
172 public async Task<WcfResponse> Delete(CriteriaRequest request)
173 {
174 var result = new WcfResponse();
175 try
176 {
177 request = ConvertRequest(request);
178 // unpack criteria data into object
179 object criteria = GetCriteria(request.CriteriaData);
181 {
182 criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
183 }
184
185 var processor = new MobileRequestProcessor();
186 var deleteRequest = new MobileCriteriaRequest(
187 request.TypeName,
188 criteria,
189 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal),
190 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext),
191 (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext),
192 request.ClientCulture,
193 request.ClientUICulture);
194
195 var deleteResponse = await processor.Delete(deleteRequest).ConfigureAwait(false);
196 if (deleteResponse.Error != null)
197 {
198 result.ErrorData = new WcfErrorInfo(deleteResponse.Error);
199 }
200 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(deleteResponse.GlobalContext);
201 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(deleteResponse.Object);
202 }
203 catch (Exception ex)
204 {
205 result.ErrorData = new WcfErrorInfo(ex);
206 }
207 finally
208 {
210 }
211 return ConvertResponse(result);
212 }
213
214#endregion
215
216#region Criteria
217
218 private static object GetCriteria(byte[] criteriaData)
219 {
220 object criteria = null;
221 if (criteriaData != null)
222 criteria = SerializationFormatterFactory.GetFormatter().Deserialize(criteriaData);
223 return criteria;
224 }
225
226#endregion
227
228#region Extention Method for Requests
229
235 protected virtual UpdateRequest ConvertRequest(UpdateRequest request)
236 {
237 return request;
238 }
239
246 {
247 return request;
248 }
249
255 protected virtual WcfResponse ConvertResponse(WcfResponse response)
256 {
257 return response;
258 }
259
260#endregion
261 }
262}
263#endif
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Class used as a wrapper for criteria based requests that use primitives
Message sent to the WCF data portal.
string ClientCulture
Serialized client culture.
string ClientUICulture
Serialized client UI culture.
byte[] Principal
Serialized data for the principal object.
byte[] CriteriaData
Serialized data for the criteria object.
byte[] GlobalContext
Serialized data for the global context object.
string TypeName
Assembly qualified name of the business object type to create.
byte[] ClientContext
Serialized data for the client context object.
Class that will be used to execute a request from a client.
Object that processes all the requests from a client
static void ClearContext()
Clears the application context and current principal.
Class that will be used to execute an Update request from a client.
Message sent to the WCF data portal.
string ClientCulture
Serialized client culture.
string ClientUICulture
Serialized client UI culture.
byte[] Principal
Serialized principal object.
byte[] GlobalContext
Serialized global context object.
byte[] ClientContext
Serialized client context object.
byte[] ObjectData
Serialized object data.
Message containing details about any server-side exception.
Definition: WcfErrorInfo.cs:20
Exposes server-side DataPortal functionality through WCF.
async Task< WcfResponse > Delete(CriteriaRequest request)
Delete a business object.
virtual WcfResponse ConvertResponse(WcfResponse response)
Override to convert the response data after it comes back from the network.
async Task< WcfResponse > Fetch(CriteriaRequest request)
Get an existing business object.
virtual CriteriaRequest ConvertRequest(CriteriaRequest request)
Override to convert the request data before it is transferred over the network.
virtual UpdateRequest ConvertRequest(UpdateRequest request)
Override to convert the request data before it is transferred over the network.
async Task< WcfResponse > Update(UpdateRequest request)
Update a business object.
async Task< WcfResponse > Create(CriteriaRequest request)
Create a new business object.
Response message returned from the WCF data portal methods.
Defines the service contract for the WCF data portal.