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

  • 相关阅读:
    实验8-1-8 报数 (20分) 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
    6-11 求自定类型元素序列的中位数 (25分)
    L2-032 彩虹瓶 (25分)
    L2-031 深入虎穴 (25分)
    L2-029 特立独行的幸福 (25分)
    L1-064 估值一亿的AI核心代码 (20分) 团体程序设计天梯赛-练习集
    7-16 一元多项式求导 (20 分) 数据结构与算法题目集(中文)
    7-28 搜索树判断 (25 分) 数据结构与算法题目集(中文)
    数据加密之SymmetricAlgorithm加密
    数据加密之RijndaelManaged加密
  • 原文地址:https://www.cnblogs.com/zyip/p/1866240.html
Copyright © 2011-2022 走看看