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
< string string >  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 < string string >  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

你可能感兴趣的:(cookie)