示例#1
0
        public Stream handlePostKeyValue(string id, Stream request)
        {
            System.ServiceModel.OperationContext        op    = System.ServiceModel.OperationContext.Current;
            System.ServiceModel.Web.WebOperationContext webop = System.ServiceModel.Web.WebOperationContext.Current;
            string content_type = webop.IncomingRequest.Headers["Content-Type"];
            string s            = "OK";

            using (StreamReader sr = new StreamReader(request))
            {
                s = sr.ReadToEnd();
            }
            if (content_type == "application/x-www-form-urlencoded")
            {
                NameValueCollection kvp;
                kvp = HttpUtility.ParseQueryString(s);
            }
            else if (content_type == "application/json")
            {
            }
            else if (content_type == "plain/text")
            {
            }
            else
            {
            }
            return(new MemoryStream(System.Text.Encoding.UTF8.GetBytes($"{s}{System.Environment.NewLine}")));
        }
示例#2
0
        public string Create(Stream streamdata)
        {
            StreamReader reader = new StreamReader(streamdata);
            string       res    = reader.ReadToEnd();


            System.ServiceModel.Web.WebOperationContext ctx = System.ServiceModel.Web.WebOperationContext.Current;
            String XBluvaltSignature = ctx.IncomingRequest.Headers["X-Cartwheel-Signature"].ToString();

            reader.Close();
            reader.Dispose();
            log.Info(XBluvaltSignature);
            if (XBluvaltSignature != null)
            {
                try
                {
                    SPServices spServices = new DefaultSPServices();
                    spServices.handleEvent(res);
                    log.Info(res);
                    return("success");
                }
                catch (Exception ex)
                {
                    // Try and handle malformed POST body
                    log.Error(ex.Message.ToString());
                    return("Error");
                }
            }
            else
            {
                log.Error("Error Logged");
                return("Error");
            }
        }
示例#3
0
        public Stream SayHello(string name)
        {
            Stream ret = null;

            try
            {
#if !true
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("function", "SayHello");
                dic.Add("name", name);
                System.ServiceModel.Web.WebOperationContext op = System.ServiceModel.Web.WebOperationContext.Current;
                var    jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                string s   = jss.Serialize(dic);
                ret = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(s));
#else
                StringBuilder sb = new StringBuilder();
                sb.Append("SayHello: ");
                sb.Append(name);
                sb.AppendLine();
                sb.Append("OK");
                sb.AppendLine();
                ret = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(sb.ToString()));
#endif
            }
            catch (Exception) { }
            return(ret);
        }
示例#4
0
        public Stream Lookup(string imei)
        {
            Stream ret = null;

            try
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("function", "Lookup");
                dic.Add("imei", imei);
                dic.Add("tac", imei.Substring(0, 8));
                dic.Add("Version", getVersion());
                Tuple <int, string, string, string> mm = lookupImei(imei);
                dic.Add("error", mm.Item1);
                dic.Add("message", mm.Item4);
                if (mm.Item1 == 0)
                {
                    dic.Add("maker", mm.Item2);
                    dic.Add("model", mm.Item3);
                    dic.Add("lastmodify", lastmodeified.ToString("s"));
                }
                System.ServiceModel.Web.WebOperationContext op = System.ServiceModel.Web.WebOperationContext.Current;
                op.OutgoingResponse.Headers.Add("Content-Type", "application/json");
                JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                string s = jss.Serialize(dic);
                ret = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(s));
            }
            catch (Exception) { }
            return(ret);
        }
示例#5
0
        private static TService HttpsCreate <TService>(string url, int TimeOut)
        {
            Uri uri = new Uri(url);

            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
            WSHttpBinding binding = new System.ServiceModel.WSHttpBinding();

            binding.SendTimeout    = new TimeSpan(0, TimeOut / 60, TimeOut % 60);
            binding.ReceiveTimeout = new TimeSpan(0, TimeOut / 60, TimeOut % 60);

            #region  设置一些配置信息
            binding.Security.Mode = SecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            #endregion

            System.ServiceModel.Web.WebOperationContext ctx = System.ServiceModel.Web.WebOperationContext.Current;
            var token = ctx.IncomingRequest.Headers["token"].ToString();

            AddressHeaderCollection addressHeaderColl;
            if (!string.IsNullOrEmpty(token))
            {
                AddressHeader   addressHeader1 = AddressHeader.CreateAddressHeader("token", "", token);
                AddressHeader[] addressHeaders = new AddressHeader[] { addressHeader1 };
                addressHeaderColl = new AddressHeaderCollection(addressHeaders);
            }
            else
            {
                addressHeaderColl = new AddressHeaderCollection();
            }
            //
            //string[] cers = ZH.Security.Client.CertUtil.GetHostCertificate(uri);
            //TODO 证书处理
            string[] cers        = "".Split('.');
            var      IdentityDns = EndpointIdentity.CreateDnsIdentity(cers[0]);
            //
            System.ServiceModel.EndpointAddress endpoint = new EndpointAddress(uri, IdentityDns, addressHeaderColl);

            ChannelFactory <TService> channelfactory = new ChannelFactory <TService>(binding, endpoint);
            foreach (OperationDescription op in channelfactory.Endpoint.Contract.Operations)
            {
                DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }
            //
            channelfactory.Credentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(Convert.FromBase64String(cers[1])); // new X509Certificate2(x509certificate);            \

            //
            //返回工厂创建
            TService tservice = channelfactory.CreateChannel();
            //
            return(tservice);
        }
示例#6
0
        public Stream Test(string name)
        {
            Stream ret = null;

            try
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("function", "Test");
                dic.Add("name", name);
                dic.Add("Version", getVersion());
                System.ServiceModel.Web.WebOperationContext op = System.ServiceModel.Web.WebOperationContext.Current;
                op.OutgoingResponse.Headers.Add("Content-Type", "application/json");
                JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                string s = jss.Serialize(dic);
                ret = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(s));
            }
            catch (Exception) { }
            return(ret);
        }
 public WebOperationContextWrapper(WebOperationContext context)
 {
     this.context = context;
 }