public T Send <T>(object data)
        {
            T val;

            using (var client = new WebClient()
            {
                BaseAddress = "http://127.0.0.1:" + PortHost.ToString()
            })
            {
                byte[] buf;
                using (var ms = new MemoryStream())
                {
                    Serializer.NonGeneric.Serialize(ms, data);
                    buf = ms.ToArray();
                }
                buf = client.UploadData("/", buf); // data is now the response
                using (var ms = new MemoryStream(buf))
                    val = Serializer.Deserialize <T>(ms);
            }
            return(val);
        }
Exemple #2
0
        public object Post(string url)
        {
            object val = null;

            using (var client = new WebClient()
            {
                BaseAddress = url
            })
            {
                byte[]          buf;
                BinaryFormatter formatter = new BinaryFormatter();
                using (var ms = new MemoryStream())
                {
                    formatter.Serialize(ms, this);
                    buf = ms.ToArray();
                }
                buf = client.UploadData("/", buf);
                using (var ms = new MemoryStream(buf))
                    val = formatter.Deserialize(ms);
            }
            return(val);
        }