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

  • 相关阅读:
    将vue文件script代码抽取到单独的js文件
    git pull 提示错误:Your local changes to the following files would be overwritten by merge
    vue和uniapp 配置项目基础路径
    XAMPP Access forbidden! Access to the requested directory is only available from the local network.
    postman与newman集成
    postman生成代码段
    Curl命令
    POST方法的Content-type类型
    Selenium Grid 并行的Web测试
    pytorch转ONNX以及TnesorRT的坑
  • 原文地址:https://www.cnblogs.com/zyip/p/1866240.html
Copyright © 2011-2022 走看看