Ejemplo n.º 1
0
        static void SendReturnInfo(Uri uri, ReturnInfo returnInfo)
        {
            byte[] bin = null;
            using (var ms = new MemoryStream())
            {
                var serializer = new DataContractSerializer(returnInfo.GetType(), AssemblyManager.GetDataContractableTypes());
                serializer.WriteObject(ms, returnInfo);
                bin = ms.ToArray();
            }

            var request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            var requestStream = request.GetRequestStreamAsync();

            requestStream.Wait();
            using (var reqStream = requestStream.Result)
            {
                reqStream.Write(bin, 0, bin.Length);
            }

            var response = request.GetResponseAsync();

            response.Wait();
            ((HttpWebResponse)response.Result).Dispose();
        }
Ejemplo n.º 2
0
        static ProtocolInfo GetProtocolInfo(Uri uri)
        {
            var protocolGet = (HttpWebRequest)WebRequest.Create(uri);

            protocolGet.Method = "POST";
            var resProtocolGet = protocolGet.GetResponseAsync();

            resProtocolGet.Wait();

            using (var httpWebResponsex = (HttpWebResponse)resProtocolGet.Result)
                using (var reader = new StreamReader(httpWebResponsex.GetResponseStream()))
                {
                    string protocol;
                    protocol = reader.ReadToEnd();
                    if (string.IsNullOrEmpty(protocol))
                    {
                        return(null);
                    }
                    using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(protocol)))
                    {
                        var serializer = new DataContractSerializer(typeof(ProtocolInfo), AssemblyManager.GetDataContractableTypes());
                        return((ProtocolInfo)serializer.ReadObject(ms));
                    }
                }
        }
Ejemplo n.º 3
0
        void LoopCore()
        {
            var context = _listener.GetContext();

            using (var response = context.Response)
            {
                ProtocolInfo protocolInfo;
                using (var reader = new StreamReader(context.Request.InputStream))
                {
                    string protocol;
                    protocol = reader.ReadToEnd();
                    if (string.IsNullOrEmpty(protocol))
                    {
                        return;
                    }
                    using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(protocol)))
                    {
                        var serializer = new DataContractSerializer(typeof(ProtocolInfo), AssemblyManager.GetDataContractableTypes());
                        protocolInfo = (ProtocolInfo)serializer.ReadObject(ms);
                    }
                }


                var returnInfo = _control.Execute(protocolInfo);


                byte[] bin = null;
                using (var ms = new MemoryStream())
                {
                    var serializer = new DataContractSerializer(returnInfo.GetType(), AssemblyManager.GetDataContractableTypes());
                    serializer.WriteObject(ms, returnInfo);
                    bin = ms.ToArray();
                }
                response.OutputStream.Write(bin, 0, bin.Length);
            }
        }