<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Silverlight Web Services Team : faults</title><link>http://blogs.msdn.com/silverlightws/archive/tags/faults/default.aspx</link><description>Tags: faults</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>What's new with web services in Silverlight 3 Beta</title><link>http://blogs.msdn.com/silverlightws/archive/2009/03/20/what-s-new-with-web-services-in-silverlight-3-beta.aspx</link><pubDate>Fri, 20 Mar 2009 13:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9492252</guid><dc:creator>SLWSTeam</dc:creator><slash:comments>14</slash:comments><comments>http://blogs.msdn.com/silverlightws/comments/9492252.aspx</comments><wfw:commentRss>http://blogs.msdn.com/silverlightws/commentrss.aspx?PostID=9492252</wfw:commentRss><description>&lt;P&gt;Silverlight 3 beta comes with a set of exciting web services features that address key customer requests.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Binary message encoding&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In Silverlight 2 the only supported binding was BasicHttpBinding, which encodes outgoing messages as text and sends them over an HTTP transport. This binding is great for interoperability with SOAP 1.1 services and is also easily debuggable since messages can be viewed in plain text on the wire using HTTP debugging tools such as &lt;A title="Fiddler HTTP debugger" href="http://www.fiddlertool.com/" mce_href="http://www.fiddlertool.com/"&gt;Fiddler&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;However as Silverlight applications go into production and grow to scale, service developers start getting concerned with the cost of hosting services. Two things in particular that we are about:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Increased server throughput&lt;/STRONG&gt; - more clients can be&amp;nbsp;connected to a&amp;nbsp;server, which means fewer servers need to be purchased.&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Decreased message size&lt;/STRONG&gt; - smaller message sizes exchanged on the wire means lower bandwidth bills&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Silverlight 3 introduces a binary message encoder, which produces significant improvements in both of the above indicators. A follow-up post is coming with some specific data on the improvements that can be expected.&lt;/P&gt;
&lt;P&gt;Binary encoding is implemented as a custom binding, there is no out-of-the-box binary binding. &lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"&gt;&amp;lt;bindings&amp;gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;customBinding&amp;gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;binding name="binaryHttpBinding"&amp;gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;binaryMessageEncoding /&amp;gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;httpTransport /&amp;gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;/binding&amp;gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;/customBinding&amp;gt;&lt;BR&gt;&amp;lt;/bindings&amp;gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"&gt;&amp;lt;endpoint address="" binding="customBinding" bindingConfiguration="binaryHttpBinding"&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;contract="Service" /&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;The BinaryMessageEncodingBindingElement can be used as part of any custom binding and so it composes easily to create things like a binary duplex binding.&lt;/P&gt;
&lt;P&gt;The binary encoder offers performance gains over the text encoder, and there should never be any regressions. This is why binary is the new default in backend service scenarios, such as where the &lt;STRONG&gt;Silverlight-enabled WCF Service&lt;/STRONG&gt; item template is used. Therefore the template has been modified to use binary. The interop cases is where binary should not be used (if the client is talking to a non-WCF service), since binary is a WCF-specific encoding: please continue to use BasicHttpBinding with text encoding in those scenarios (for example accessing ASMX services).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Duplex object model simplification&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Duplex is an innovative Silverlight 2 feature which allows the service to send data to the client without the client manually polling for the data ("smart" polling still occurs on the network layer, but the user does not need to know).&amp;nbsp;However there were two significant limitations in the Silverlight&amp;nbsp;2 duplex&amp;nbsp;object model:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Channel programming had to be used and&lt;/LI&gt;
&lt;LI&gt;Serialization was not supported so a Message programming model had to be used.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Silverlight 3 lifts these restrictions and introduces &lt;STRONG&gt;Add Service Reference support for duplex services&lt;/STRONG&gt;.&amp;nbsp;Familiar-looking proxies are now generated, greatly reducing&amp;nbsp;the amount of&amp;nbsp;Silverlight code that is needed to access a duplex service. A simple stock ticker client implementation, which previously took 203 lines of code, &lt;STRONG&gt;can now be reduced to a mere 48 lines of code, a 76% reduction in code size.&lt;/STRONG&gt; Not to mention that the channel-based code was complex and very error-prone due to its use of async patterns. Here is a snippet showing the crux of the new object model, in the context of the stock ticker example:&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;private&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; Button_Click(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; sender, System.Windows.RoutedEventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ServiceClient proxy = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ServiceClient(binding, address);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;proxy.ReceiveCallbackCompleted += &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;EventHandler&lt;/SPAN&gt;&amp;lt;ReceiveCallbackCompletedEventArgs&amp;gt;(proxy_ReceiveCallbackCompleted);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;proxy.StartAsync(symbol.Text);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;void&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt; proxy_ReceiveCallbackCompleted(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; sender, ReceiveCallbackCompletedEventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (e.Error == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;price.Text = e.price.ToString();&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt; mso-no-proof: yes"&gt;}&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 9pt"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;P&gt;Note that receiving the callback from the server is now just a matter of attaching a callback to an event. Also note the fact that we are working with CLR types and not Message objects, so serialization is now enabled. We have updated &lt;A title="Duplex documentation" href="http://msdn.microsoft.com/en-us/library/dd470105(VS.96).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470105(VS.96).aspx"&gt;our documentation&lt;/A&gt; with&amp;nbsp;a walkthrough of how to use the new object model. In addition, &lt;A title="Duplex chat server" href="http://code.msdn.microsoft.com/silverlightws/Release/ProjectReleases.aspx?ReleaseId=2401" mce_href="http://code.msdn.microsoft.com/silverlightws/Release/ProjectReleases.aspx?ReleaseId=2401"&gt;Eugene's duplex chat server implementation&lt;/A&gt;, which has proven very popular, has also been updated with the new OM.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Faults support&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In Silverlight 2 if an unexpected exception occurred in the service, the fault would not be propagated to the Silverlight client. Instead of getting&amp;nbsp;the exception propagated to the user,&amp;nbsp;Silverlight would throw an unhelpful&amp;nbsp;&lt;STRONG&gt;CommunicationException&lt;/STRONG&gt; which carries no useful information.&amp;nbsp;There were two reasons for this: (1) faults are returned with a 500 status code, and the browser networking stack prevents Silverlight from reading the body of such a response, and (2) Silverlight did not support he necessary client-side logic to convert the fault message into an exception that can be surfaced to the user. These limitation made it very difficult to debug services from Silverlight. &lt;/P&gt;
&lt;P&gt;In Silverlight 3 Beta&amp;nbsp;limitation (1) is unfortunately still present.&amp;nbsp;To work around this issue&amp;nbsp;&lt;A title="Faults documentation" href="http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470096(VS.96).aspx"&gt;our documentation&lt;/A&gt;&amp;nbsp;provides a WCF endpoint behavior, which can be applied to your WCF service to switch the response code from 500 to 200. With this response code the message will be accessible to Silverlight and we can address limitation (2). In Silverlight 3, we have added the necessary client-side OM to surface faults to the user. Look out for helpful &lt;STRONG&gt;FaultException &lt;/STRONG&gt;and &lt;STRONG&gt;FaultException&amp;lt;ExceptionDetail&amp;gt; &lt;/STRONG&gt;exceptions which will help you debug your service. Also please see the documentation page linked earlier for a full description of the faults object model in Silverlight.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;New security mode&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;A common scheme used to secure services for use by Silverlight clients is browser-based authentication. However browser-based authetnication is not safe to use if your service is accessible from any domain via a cross-domain policy file. This would expose your service to &lt;A title="Cross Site Request Forgery" href="http://en.wikipedia.org/wiki/Cross-site_request_forgery" mce_href="http://en.wikipedia.org/wiki/Cross-site_request_forgery"&gt;CSRF&lt;/A&gt; type attacks, where cached browser credentials can be used by malicious apps to access your sercure service without the user's knowledge. &lt;/P&gt;
&lt;P&gt;Silverlight 3 introduces a new security mode called &lt;STRONG&gt;TransportSecurityWithMessageCredential &lt;/STRONG&gt;to address this configuration. In this mode, the credentials are included in every outgoing message to the service, and the service verifies those credentials on the SOAP layer. However since the credentials are in plain text inside the message the transport needs to be secure so we use HTTPS.&lt;/P&gt;
&lt;P&gt;A more detailed walktrhough of valid Silverlight security configurations will follow.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Command-line proxy generation&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In Silverlight 2 &lt;STRONG&gt;Add Service Reference &lt;/STRONG&gt;as part of Visual Studio is the only way to generate proxies for Silverlight clients. In Silverlight 3 we are introducing a command-line tool called &lt;STRONG&gt;slsvcutil.exe&lt;/STRONG&gt;, which allows customized command-line proxy generation. Using the tool, proxies can now be generated as part of your build process for greater robustness. The slsvcutil.exe tool is fully described in this &lt;A title="slsvcutil.exe documentation" href="http://msdn.microsoft.com/en-us/library/dd470117(VS.96).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470117(VS.96).aspx"&gt;documentation topic&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Thanks for reading through this, and please stay tuned for some in-depth posts about these new features.&lt;/P&gt;
&lt;P&gt;Yavor Georgiev&lt;BR&gt;Program Manager, Silverlight Web Services Team&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9492252" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/silverlightws/archive/tags/mix/default.aspx">mix</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/samples/default.aspx">samples</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/soap/default.aspx">soap</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/duplex/default.aspx">duplex</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/security/default.aspx">security</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/binary/default.aspx">binary</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/faults/default.aspx">faults</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/slsvcutil/default.aspx">slsvcutil</category></item></channel></rss>