ASP. NET shared sessions of the WCF and IIS hosts

Source: Internet
Author: User

1. Create a WCF Project

 
Using system; using system. collections. generic; using system. LINQ; using system. runtime. serialization; using system. servicemodel; using system. text; using system. web; using system. servicemodel. activation; namespace wcfaspsession {[aspnetcompatibilityrequirements (requirementsmode = aspnetcompatibilityrequirementsmode. allowed)] public class service1: iservice1 {public int add (INT value) {int result = getresult () + value; httpcontext. current. session ["result"] = result; return result;} public int getresult () {If (httpcontext. current. session ["result"] = NULL) {httpcontext. current. session ["result"] = 0;} return (INT) httpcontext. current. session ["result"] ;}}

2. Create a. SVC file in the WEB Project

<% @ Servicehost Language = "C #" DEBUG = "true" service = "wcfaspsession. service1" %>

3. modify web. config

Add <servicehostingenvironment aspnetcompatibilityenabled = "true"> </servicehostingenvironment> and set allwocookies to true.

<System. servicemodel> <bindings> <wshttpbinding> <binding name = "canonical" closetimeout = "00:01:00" opentimeout = "00:01:00" receivetimeout = "00:10:00" sendtimeout = "00:01:00" bypassproxyonlocal = "false" transactionflow = "false" hostnamecomparisonmode = "strongwildcard" maxbufferpoolsize = "524288" maxcompute edmessagesize = "65536" messageencoding = "text" textencoding = "UTF-8" usedefawebwebproxy = "Tru E "allowcookies =" true "> <readerquotas maxdepth =" 32 "maxstringcontentlength =" 8192 "maxarraylength =" 16384 "maxbytesperread =" 4096 "maxnametablecharcount =" 16384 "/> <reliablesession ordered = "true" inactivitytimeout = "00:10:00" enabled = "false"/> <security mode = "message"> <transport clientcredentialtype = "Windows" proxycredentialtype = "NONE" Realm = "" /> <message clientcredentialtype = "Windows" negotiateser Vicecredential = "true" algorithmsuite = "default"/> </Security> </binding> </wshttpbinding> </bindings> <client> <endpoint address = "http: // localhost: 8000/service1.svc "binding =" wshttpbinding "bindingconfiguration =" canonical "Contract =" servicereference1.iservice1 "name =" canonical "> <identity> <DNS value =" localhost "/> </identity> </Endpoint> </client> <servicehostingenviro Nment aspnetcompatibilityenabled = "true"> </servicehostingenvironment> <services> <service name = "wcfaspsession. service1 "> <endpoint address =" "binding =" wshttpbinding "Contract =" wcfaspsession. iservice1 "> <! -- Upon deployment, the following identity element shoshould be removed or replaced to reflect the identity under which the deployed service runs. if removed, WCF will infer an appropriate identity automatically. --> <identity> <DNS value = "localhost"/> </identity> </Endpoint> <! -- Metadata endpoints --> <! -- The metadata exchange endpoint is used by the Service to describe itself to clients. --> <! -- This endpoint does not use a secure binding and shoshould be secured or removed before deployment --> <endpoint address = "mex" binding = "mexhttpbinding" Contract = "imetadataexchange"/> </ service> </services> <behaviors> <servicebehaviors> <behavior> <! -- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <servicemetadata httpgetenabled = "true"/> <! -- To receive exception details in faults for debugging purposes, set the value below to true. set to false before deployment to avoid disclosing exception information --> <servicedebug includeexceptiondetailinfaults = "false"/> </behavior> </servicebehaviors> </behaviors> </system. servicemodel> demo sample source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.