public static object Deserialize(Type type, Stream stream, DataFormat format) { object data = null; switch (format) { case DataFormat.JSON: data = WrappedJsonDeserializer.Instance.DeserializeFromStream(type, stream); break; case DataFormat.XML: data = WrappedXmlSerializer.DeserializeFromStream(type, stream); break; case DataFormat.ProtoBuf: data = Serializer.NonGeneric.Deserialize(type, stream); break; case DataFormat.BJJSON: data = jsonSerializer.Deserialize(type, stream); break; case DataFormat.BJBIN: data = binarySerializer.Deserialize(type, stream); break; default: throw new NotSupportedException(format + " is not supported."); } return(data); }
public object GetRequest(IHttpRequest httpReq, string operationName) { var requestType = GetRequestType(operationName, httpReq.ServicePath); AssertOperationExists(operationName, requestType); if (httpReq.ContentLength <= 0) { throw new ArgumentNullException("Missing request body"); } try { // Deserialize to soap11 envelope var soap11Envelope = WrappedXmlSerializer.DeserializeFromStream <Envelope>(httpReq.InputStream); // check existence of the request xml element if (soap11Envelope != null && soap11Envelope.Body != null && soap11Envelope.Body.Any.Count > 0) { // Get request xml element var requestXmlElement = soap11Envelope.Body.Any[0]; if (requestXmlElement != null) { // Get request xml var requestXml = requestXmlElement.OuterXml; if (!string.IsNullOrEmpty(requestXml)) { // Deserialize to object of request type return(WrappedXmlSerializer.DeserializeFromString(requestXml, requestType)); } } } } catch (Exception ex) { var msg = "Could not deserialize soap11 request into instance of {0}'\nError: {1}" .Fmt(requestType, ex); throw new SerializationException(msg); } throw new ArgumentNullException("Invalid soap11 request message"); }