zoukankan      html  css  js  c++  java
  • WCF cookie



    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    using System.Web.Security;
    using System.ServiceModel.Web;


    namespace MvcApplication2
    {
        
    // NOTE: If you change the interface name "IService2" here, you must also update the reference to "IService2" in Web.config.
        [ServiceContract]
        
    public interface IService2
        {


            [OperationContract]
            [WebInvoke(RequestFormat 
    = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, Method = "GET")]
            
    string DoWork();

            [OperationContract]
            
    bool Login(string user, string pwd);

            [OperationContract]
            System.Collections.Generic.List
    <long> GetRecordIDList();


            [OperationContract]
            
    string GetRecordById(long id);

            [OperationContract]
            System.Collections.Generic.Dictionary
    <stringstring> GetLastRecords(int count);

            [OperationContract]
            
    bool UpdateRecordStatus(long id, byte status);




        }
    }


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;

    using System.Web;
    using System.Web.Security;
    using System.ServiceModel.Activation;
    using System.ServiceModel.Web;



    namespace MvcApplication2
    {
        
    // NOTE: If you change the class name "Service2" here, you must also update the reference to "Service2" in Web.config.
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]  
        
    public class Service2 : IService2
        {

            
    public string DoWork()
            {
                
    return System.DateTime.Now.ToString();
            }

            
    protected bool Validate()
            {
                HttpCookie hc 
    = HttpContext.Current.Request.Cookies["u"];
                
    if (hc != null)
                {
                    
    string v = hc.Value;
                    
    return true;
                }
                
    return false;
                
    //if()
            }

            
    public bool Login(string user, string pwd)
            {
                
    if (user == pwd)
                {
                    HttpCookie hc 
    = new HttpCookie("u");
                    hc.Value 
    = user;
                    HttpContext.Current.Response.Cookies.Add(hc);
                    
    return true;
                }
                
    return true;
            }

            
    public List<long> GetRecordIDList()
            {
                
    throw new NotImplementedException();
            }

            
    public string GetRecordById(long id)
            {
                
    if (Validate())
                {
                    
    return "abc";
                }
                
    return "0";
            }

            
    public Dictionary<stringstring> GetLastRecords(int count)
            {
                
    throw new NotImplementedException();
            }

            
    public bool UpdateRecordStatus(long id, byte status)
            {
                
    throw new NotImplementedException();
            }


        }
    }

    代码

     
    <system.serviceModel>
        
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />    
      
    <services>
        
    <service behaviorConfiguration="MvcApplication2.Service2Behavior"
          name
    ="MvcApplication2.Service2">
          
    <endpoint address="" binding="wsHttpBinding" contract="MvcApplication2.IService2">
            
    <identity>
              
    <dns value="localhost" />
            
    </identity>
          
    </endpoint>
          
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        
    </service>      
      
    </services>  
         
        
    <behaviors>      
          
    <serviceBehaviors>               
            
    <behavior name="MvcApplication2.Service2Behavior">
              
    <serviceMetadata httpGetEnabled="true" />
              
    <serviceDebug includeExceptionDetailInFaults="false" />
            
    </behavior>                
          
    </serviceBehaviors>
        
    </behaviors>
      
    </system.serviceModel>


    http://www.cnblogs.com/shanyou/archive/2009/09/06/1561429.html 

    http://www.cnblogs.com/artech/archive/2009/06/25/1511165.html

     http://msdn.microsoft.com/zh-cn/library/bb398778.aspx

  • 相关阅读:
    程序员佛祖保佑无bug、发发发 -注释代码
    27 友盟项目--azkaban资源调度
    26 友盟项目--数据可视化
    25 友盟项目--sqoop从hive导出数据到mysql
    24 友盟项目--优化-flume限速拦截、flume自定义源防丢失--改造exec源守护线程监控目录(防丢失)redis维护key(去重)
    23 友盟项目--sparkstreaming对接kafka、集成redis--从redis中查询月留存率
    22 友盟项目--sparkstreaming对接kafka、集成redis--从redis中存储用户使用app的最小时间戳min , 最大时间戳max
    21 友盟项目--统计连续活跃用户、近期流失用户、留存用户--创建表并插入选择出的数据
    20 友盟项目--统计月活率、沉默用户、周回流用户--创建表并插入选择出的数据
    19 友盟项目--统计新增用户---日新增、周新增、月新增--创建表并插入选择出的数据
  • 原文地址:https://www.cnblogs.com/zyip/p/1866240.html
Copyright © 2011-2022 走看看