{"id":731,"date":"2008-07-21T12:44:10","date_gmt":"2008-07-21T11:44:10","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/731-wcf-sessions-with-silverlight-and-flex.html"},"modified":"2008-07-21T12:44:10","modified_gmt":"2008-07-21T11:44:10","slug":"wcf-sessions-with-silverlight-and-flex","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/731-wcf-sessions-with-silverlight-and-flex.html","title":{"rendered":"WCF Sessions with Silverlight and Flex"},"content":{"rendered":"<p>I wanted to adapt my <a href=\"http:\/\/www.itwriting.com\/blog\/simple-crud-with-silverlight-20\">Silverlight CRUD sample<\/a> (which I also <a href=\"http:\/\/www.theregister.co.uk\/2008\/07\/17\/flex_gets_soapy\/\">ported to Adobe Flex<\/a>) to fix a glaring weakness, which is that any user can amend any entry.<\/p>\n<p>I decided to add some logic that allows editing or deleting of only those rows created during the current session. The idea is that a user can amend the entry just made, but not touch any of the others.<\/p>\n<p>WCF has its own <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms733040.aspx\">session management<\/a> but this is not supported by the BasicHttpBinding which is <strong>required<\/strong> by Silverlight.<\/p>\n<p>Fortunately you can use ASP.NET sessions instead. This means setting your WCF web service for ASP.NET compatibility:<\/p>\n<blockquote>\n<p>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]<\/p>\n<\/blockquote>\n<p>Then you can write code using the HttpContext.Current.Session object.<\/p>\n<p>This depends on cookies being enabled on the client. In my simple case it worked fine, in both Silverlight and Flex. In a real app you would probably want to use HTTPS.<\/p>\n<p>I\u2019d post the sample but unfortunately my Windows web space doesn\u2019t support WCF.<\/p>\n<div class=\"wlWriterSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:114d4a8a-4984-497a-864c-e59226476020\" style=\"padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/wcf\" rel=\"tag\">wcf<\/a>, <a href=\"http:\/\/technorati.com\/tags\/sessions\" rel=\"tag\">sessions<\/a>, <a href=\"http:\/\/technorati.com\/tags\/asp.net\" rel=\"tag\">asp.net<\/a>, <a href=\"http:\/\/technorati.com\/tags\/flex\" rel=\"tag\">flex<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to adapt my Silverlight CRUD sample (which I also ported to Adobe Flex) to fix a glaring weakness, which is that any user can amend any entry. I decided to add some logic that allows editing or deleting of only those rows created during the current session. The idea is that a user &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/731-wcf-sessions-with-silverlight-and-flex.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WCF Sessions with Silverlight and Flex<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,44,55,77,80,96],"tags":[],"class_list":["post-731","post","type-post","status-publish","format-standard","hentry","category-net","category-adobe","category-internet","category-microsoft","category-silverlight","category-software-development","category-web-authoring"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=731"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/731\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}