232 |
232 |
string requestXML = HttpUtility.UrlDecode(text);
|
233 |
233 |
Console.WriteLine(requestXML);
|
234 |
234 |
|
|
235 |
// prepare the type:
|
235 |
236 |
Request newRequest = new Request();
|
236 |
|
Request requestDeserialized = XmlCommunication.Deserialize(newRequest, requestXML);
|
|
237 |
Request requestDeserialized = null;
|
|
238 |
try
|
|
239 |
{
|
|
240 |
requestDeserialized = XmlCommunication.Deserialize(newRequest, requestXML);
|
|
241 |
}
|
|
242 |
catch
|
|
243 |
{
|
|
244 |
Console.WriteLine("wrong format of request!");
|
|
245 |
|
|
246 |
// don't bother to send anything:
|
|
247 |
continue;
|
|
248 |
}
|
|
249 |
|
237 |
250 |
|
|
251 |
// response headers:
|
238 |
252 |
HttpListenerResponse response = context.Response;
|
239 |
253 |
response.AddHeader("Access-Control-Allow-Credentials", "true");
|
240 |
254 |
response.AddHeader("Access-Control-Expose-Headers", "ETag");
|
... | ... | |
242 |
256 |
response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
243 |
257 |
response.AddHeader("Access-Control-Allow-Origin", "*");
|
244 |
258 |
|
245 |
|
|
|
259 |
// get the prediction from the model:
|
246 |
260 |
Response responsePrediction = predictionController.Predict(requestDeserialized);
|
247 |
261 |
|
248 |
262 |
int rand = new Random().Next(1, 10);
|
249 |
263 |
string msg = "OK " + rand;
|
250 |
264 |
|
|
265 |
// build the xml from the prediction: - TODO mbe an exception can happen here as well? - it shouldnt
|
251 |
266 |
msg = XmlCommunication.Serialize(responsePrediction);
|
252 |
267 |
|
253 |
|
byte[] buffer = Encoding.UTF8.GetBytes(msg);
|
254 |
268 |
|
|
269 |
// send the response:
|
|
270 |
byte[] buffer = Encoding.UTF8.GetBytes(msg);
|
255 |
271 |
response.ContentLength64 = buffer.Length;
|
256 |
272 |
Stream st = response.OutputStream;
|
257 |
273 |
st.Write(buffer, 0, buffer.Length);
|
258 |
274 |
|
259 |
|
|
|
275 |
// close
|
260 |
276 |
context.Response.Close(); // ?? Works better with this, if this line is absent, the client gets 'stuck' after approximately 6 messages
|
261 |
277 |
}
|
262 |
278 |
else
|
Re #8943. Prepared getting predictions from Model.