<?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 : crossdomain</title><link>http://blogs.msdn.com/silverlightws/archive/tags/crossdomain/default.aspx</link><description>Tags: crossdomain</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Debugging Web Service Usage in Silverlight 2</title><link>http://blogs.msdn.com/silverlightws/archive/2008/04/16/debugging-web-service-usage-in-silverlight-2.aspx</link><pubDate>Wed, 16 Apr 2008 21:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8399338</guid><dc:creator>SLWSTeam</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/silverlightws/comments/8399338.aspx</comments><wfw:commentRss>http://blogs.msdn.com/silverlightws/commentrss.aspx?PostID=8399338</wfw:commentRss><description>&lt;P&gt;(Cross-posted from &lt;A href="http://eugeneos.blogspot.com/2008/04/debugging-web-service-usage-in.html"&gt;http://eugeneos.blogspot.com/2008/04/debugging-web-service-usage-in.html&lt;/A&gt;)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Silverlight 2 Beta1 makes it easy to use Web Services based on either the WCF technology (Windows Communication Foundation), the “.asmx” technology (ASP.NET Web Services), or practically any other SOAP platform. &lt;/P&gt;
&lt;P&gt;Unfortunately, when something goes wrong with service consumption, you often run into cryptic and incomprehensible error messages that don’t help you much. We are looking into various ways to make this better by the time we fully ship Silverlight 2, but for now I hope that this post will be useful in helping you debug common problems. Here are the things you can try:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;Does your proxy compile?&lt;/SPAN&gt;&lt;/U&gt; &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;After you use the “Add Service Reference” dialog to add a reference to a service, try building your project. If you get compilation issues in the generated proxy code, you are probably using a service that uses some feature that is not supported in Beta1. We are trying to fix all or most of these by the time we ship, but for now the easiest thing to do is to find the offending code in the generated proxy and just remove it – naturally this workaround does not work in all cases :) Some common things that will cause non-compilable proxies in Beta1: &lt;/P&gt;
&lt;P&gt;- Using custom SOAP headers in your service &lt;BR&gt;- Using custom SOAP faults &lt;BR&gt;- Using “wildcard” schema in your service like &lt;STRONG&gt;xsd:any&lt;/STRONG&gt; or &lt;STRONG&gt;xsd:anyattribute&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;And specifically if your service is a WCF (or in some cases .ASMX) service: &lt;/P&gt;
&lt;P&gt;- Using XML types like XmlElement/XElement/XmlNode[]/XmlAttribute/etc. in your service &lt;BR&gt;- Using Datasets in your service &lt;BR&gt;- Using types that implement ISerializable in your service (except for collections) &lt;BR&gt;- Using WCF Transactions features &lt;BR&gt;- Using the Stream type in your service &lt;BR&gt;- Using MessageHeaderAttribute in Message Contracts &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;Check the Configuration&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;The next step is to check whether the service is configured correctly. You should have a file called &lt;STRONG&gt;&lt;EM&gt;ServiceReferences.ClientConfig &lt;/EM&gt;&lt;/STRONG&gt;generated by Add Service Reference. It actually doesn’t do anything at all in Beta1! This (understandably) confuses a lot of people. Starting with Beta2, we will actually start using this file, but for now any changes that you’ll make in it won’t actually affect anything. &lt;/P&gt;
&lt;P&gt;However, the file is still useful for debugging. Look in the file – it should look something like this: &lt;/P&gt;
&lt;P&gt;&lt;SPAN style="COLOR: #000099"&gt;&amp;lt;configuration&amp;gt;&lt;BR&gt;&amp;lt;system.serviceModel&amp;gt; &lt;BR&gt;&amp;lt;client&amp;gt; &lt;BR&gt;&lt;STRONG&gt;&amp;lt;endpoint address="&lt;SPAN style="COLOR: #990000"&gt;http://localhost:5678/TestService.svc&lt;/SPAN&gt;" binding="&lt;SPAN style="COLOR: #990000"&gt;basicHttpBinding&lt;/SPAN&gt;" contract="MyProject.ITestService" name="default" /&amp;gt; &lt;BR&gt;&lt;/STRONG&gt;&amp;lt;/client&amp;gt; &lt;BR&gt;&amp;lt;/system.serviceModel&amp;gt; &lt;BR&gt;&amp;lt;/configuration&amp;gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="COLOR: #000099"&gt;&lt;SPAN style="FONT-FAMILY: Courier New"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Notice that it has exactly one &lt;STRONG&gt;&lt;EM&gt;endpoint&lt;/EM&gt;&lt;/STRONG&gt; element for the service you just added a reference to, and the binding is basicHttpBinding. &lt;/P&gt;
&lt;P&gt;If you don’t see an &lt;STRONG&gt;&lt;EM&gt;endpoint&lt;/EM&gt;&lt;/STRONG&gt; element for your service, chances are your service wasn’t actually configured correctly for Silverlight consumption. Silverlight can only talk to simple SOAP services at this point – only SOAP 1.1, without any advanced WS-* protocols like WS-Addressing or WS-Security. If you are using “.ASMX” web services, they should just default to this simple configuration. If you are using WCF services, you need to check the configuration on the service side. Open &lt;STRONG&gt;&lt;EM&gt;web.config &lt;/EM&gt;&lt;/STRONG&gt;in your service-side project and find a place that looks like the following (usually towards the end): &lt;/P&gt;
&lt;P&gt;&lt;SPAN style="COLOR: #000099"&gt;&amp;lt;system.serviceModel&amp;gt; &lt;BR&gt;... &lt;BR&gt;&amp;lt;services&amp;gt; &lt;BR&gt;&amp;lt;service name="MyProject.TestService"&amp;gt; &lt;BR&gt;&lt;STRONG&gt;&amp;lt;endpoint address="" binding="&lt;SPAN style="COLOR: #990000"&gt;basicHttpBinding&lt;/SPAN&gt;" contract="&lt;SPAN style="COLOR: #990000"&gt;MyProject.ITestService&lt;/SPAN&gt;" /&amp;gt; &lt;BR&gt;&lt;/STRONG&gt;&amp;lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&amp;gt; &lt;BR&gt;... &lt;BR&gt;&amp;lt;/service&amp;gt; &lt;BR&gt;&amp;lt;/services&amp;gt; &lt;BR&gt;&amp;lt;/system.serviceModel&amp;gt;&lt;/SPAN&gt; &lt;/P&gt;
&lt;P&gt;Find the &lt;STRONG&gt;&lt;EM&gt;endpoint&lt;/EM&gt;&lt;/STRONG&gt; whose “contract” attribute refers to your service. Make sure that the “binding” attribute is set to “basicHttpBinding”. Unfortunately the default for WCF is “wsHttpBinding”, but it doesn’t work with Silverlight. We are hoping to ship a Visual Studio item template in the future (“Add New Item… Silverlight-enabled WCF Service”) that will have a number of Silverlight-friendly defaults, including the correct binding. &lt;/P&gt;
&lt;P&gt;It is ok to have other &lt;STRONG&gt;&lt;EM&gt;endpoint&lt;/EM&gt;&lt;/STRONG&gt; elements for other contracts with other bindings - for example, do not change the "mexHttpBinding" in the second &lt;STRONG&gt;&lt;EM&gt;endpoint&lt;/EM&gt;&lt;/STRONG&gt; element above. &lt;/P&gt;
&lt;P&gt;You should check your service-side configuration even if the client-side &lt;STRONG&gt;&lt;EM&gt;ServiceReferences.ClientConfig &lt;/EM&gt;&lt;/STRONG&gt;appears to be correct. &lt;/P&gt;
&lt;P&gt;If &lt;STRONG&gt;&lt;EM&gt;ServiceReferences.ClientConfig &lt;/EM&gt;&lt;/STRONG&gt;contains more than one &lt;STRONG&gt;&lt;EM&gt;endpoint&lt;/EM&gt;&lt;/STRONG&gt; for your service, you may need to use a more complicated constructor to new up your service proxy – the one that takes a Binding and an EndpointAddress. Not to worry – just pass a new BasicHttpBinding() and a new EndpointAddress built from the URL of your service. &lt;/P&gt;
&lt;P&gt;By the way, our long-term (post-Beta1) plans for the config file are described here: &lt;A href="http://blogs.msdn.com/suwatch/archive/2008/04/07/tutorial-using-silverlight-web-service-client-configuration.aspx" mce_href="http://blogs.msdn.com/suwatch/archive/2008/04/07/tutorial-using-silverlight-web-service-client-configuration.aspx"&gt;http://blogs.msdn.com/suwatch/archive/2008/04/07/tutorial-using-silverlight-web-service-client-configuration.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;Check if the Service is Running&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;Before looking for problems on the Silverlight side, it is useful to first check whether the service itself is working. A quick-and-dirty way to check is to just type the service address into a web browser (not the address you typed into the “Add Service Reference” dialog, but the address you can find in &lt;STRONG&gt;&lt;EM&gt;ServiceReferences.ClientConfig&lt;/EM&gt;&lt;/STRONG&gt;). In many cases, the “service help page” feature will be turned on and you will see either a page indicating that the service is running, or an error page which you can use as a starting point for debugging. &lt;/P&gt;
&lt;P&gt;A more reliable way to test whether the service is working is to use a test tool such as the WCF Test Client (&lt;A href="http://msdn2.microsoft.com/en-us/library/bb552364.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb552364.aspx"&gt;http://msdn2.microsoft.com/en-us/library/bb552364.aspx&lt;/A&gt;) to try and talk to the service. &lt;/P&gt;
&lt;P&gt;Finally, an almost sure-fire but sometimes lengthy way of finding out whether the problem is with the Silverlight code or with the service code is to try using the service without Silverlight :) Just create a new project of type “Console Application”, do an Add Service Reference to that project just like in Silverlight, and write service consumption code inside Main() – again, just like in Silverlight. Use Console.WriteLine to show the results. &lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;Check for Cross-Domain Issues&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;Start your Silverlight application. Note the URL that appears in the browser (e.g. &lt;STRONG&gt;http://localhost:1111/something/MyGraphicalApp.aspx&lt;/STRONG&gt;) – this is your “Application URL”. (Actually, what matters here is the URL of the XAP file, e.g. &lt;STRONG&gt;http://localhost:1111/somethingelse/MyGraphicalApp.xap&lt;/STRONG&gt;, but in most simple cases this URL would be in the same domain as the hosting web page, so I’m ignoring the difference for now). Then, look at the URL in the ServiceReferences.ClientConfig file – e.g. &lt;STRONG&gt;http://localhost:5678/foo/TestService.svc &lt;/STRONG&gt;or &lt;STRONG&gt;local.live.com/SearchService/LocalSearch.asmx&lt;/STRONG&gt; - this is your “Service URL”. &lt;/P&gt;
&lt;P&gt;In Beta1, both the “Application URL” and the “Service URL” must be HTTP URLs (not HTTPS) for service consumption to work. This is the first thing to check. &lt;/P&gt;
&lt;P&gt;Also, a common mistake is to run your Silverlight application from a &lt;STRONG&gt;file:// &lt;/STRONG&gt;Application URL, resulting in cross-domain issues. Sometimes, you run into this if you just hit F5 to run your Silverlight app – instead, right-click on the .aspx page in your project and choose “View in Browser”. &lt;/P&gt;
&lt;P&gt;Now you need to figure out the domains for these URLs. The domain is just the basically everything between &lt;STRONG&gt;http:// &lt;/STRONG&gt;and the first slash &lt;STRONG&gt;/ &lt;/STRONG&gt;after that, including the port number (assumed to be 80 if not present). If the domain of the Application URL is different in any way from the domain of the Service URL in any way (even if it’s just a port number difference, or just one part of the domain name is different), you have a cross-domain situation. For example, if your app is at &lt;STRONG&gt;http://localhost:1111/something/MyGraphicalApp.aspx &lt;/STRONG&gt;and it is trying to call into &lt;STRONG&gt;http://localhost:5678/foo/TestService.svc&lt;/STRONG&gt;, you have a cross-domain situation because &lt;STRONG&gt;localhost:1111 &lt;/STRONG&gt;is different from &lt;STRONG&gt;localhost:5678&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;Silverlight documentation tells you that if you are in a cross-domain situation, you need to have a “cross-domain policy file” (&lt;STRONG&gt;&lt;EM&gt;clientaccesspolicy.xml &lt;/EM&gt;&lt;/STRONG&gt;or &lt;STRONG&gt;&lt;EM&gt;crossdomain.xml&lt;/EM&gt;&lt;/STRONG&gt;) present if you want services to work. There is an easy way to check if you have everything set up correctly: Just open a browser and browse to &lt;STRONG&gt;http://&lt;/STRONG&gt;&lt;EM&gt;service_domain&lt;/EM&gt;&lt;STRONG&gt;/clientaccesspolicy.xml &lt;/STRONG&gt;and &lt;STRONG&gt;http://&lt;/STRONG&gt;&lt;EM&gt;service_domain&lt;/EM&gt;&lt;STRONG&gt;/crossdomain.xml&lt;/STRONG&gt;. If at least one of these is present, valid and allows cross-domain access – you’re fine. If not, you need to make sure at least one of these files is present. &lt;/P&gt;
&lt;P&gt;A common mistake is to put the cross-domain policy file not directly at the root of the domain – for example, at &lt;STRONG&gt;http://localhost:5678/foo/clientaccesspolicy.xml &lt;/STRONG&gt;instead of at &lt;STRONG&gt;http://localhost:5678/clientaccesspolicy.xml&lt;/STRONG&gt;. It is easy to run into this situation when working with older (.NET 2.0) projects – see &lt;A href="http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx" mce_href="http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx"&gt;http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;Also, make sure to check the syntax of these files – an error in parsing will be treated essentially the same way as if the file was not there. Also note that &lt;STRONG&gt;&lt;EM&gt;clientaccesspolicy.xml &lt;/EM&gt;&lt;/STRONG&gt;and &lt;STRONG&gt;&lt;EM&gt;crossdomain.xml &lt;/EM&gt;&lt;/STRONG&gt;have different syntax – make sure you use the appropriate content for the file you choose. &lt;/P&gt;
&lt;P&gt;A neat trick for adding cross-domain policy files to WCF services that are not hosted in IIS is described here: &lt;A href="http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx" mce_href="http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx"&gt;http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;Enable Exceptions&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;Normally, Silverlight does not give you much information in exception messages. This decision was made to make the Silverlight download size smaller (exceptions take up a lot of space, especially once they’re translated into all of the languages Silverlight supports). You can read more about this, and find out how to turn on full exceptions for debugging, here: &lt;A href="http://blogs.msdn.com/silverlightws/archive/2008/04/06/getting-full-exceptions-in-silverlight-2-beta-1.aspx" mce_href="http://blogs.msdn.com/silverlightws/archive/2008/04/06/getting-full-exceptions-in-silverlight-2-beta-1.aspx"&gt;http://blogs.msdn.com/silverlightws/archive/2008/04/06/getting-full-exceptions-in-silverlight-2-beta-1.aspx&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Also, if you are using a WCF service, WCF does not normally return much information about server-side exceptions. This is a security measure: you normally don’t want to expose internal information about your service to the outside world. However, during debugging, you can change this by following the steps here: &lt;A href="http://blogs.devdeo.com/carlos.medina/PermaLink,guid,b3bff742-0ec9-4f5c-a178-625220a46652.aspx" mce_href="http://blogs.devdeo.com/carlos.medina/PermaLink,guid,b3bff742-0ec9-4f5c-a178-625220a46652.aspx"&gt;http://blogs.devdeo.com/carlos.medina/PermaLink,guid,b3bff742-0ec9-4f5c-a178-625220a46652.aspx&lt;/A&gt;. Make sure to turn it off once you’re done debugging! &lt;/P&gt;
&lt;P&gt;Finally, this seems obvious but a lot of people forget about it for some reason - when you get an exception, don’t just look at the exception itself - look at its innerException, and the innerException inside it, etc. Especially in web service scenarios, the truly useful exceptions are often “wrapped” in several layers. &lt;/P&gt;
&lt;P&gt;Unfortunately, even with all of the steps above, you often still won’t see much useful information when a web service call fails. This is due to a pretty fundamental limitation of Silverlight Beta1 (that unfortunately may stay around even after the Beta) – the lack of support for SOAP Faults. So, to truly debug, you need to see what is actually going on – this is what the next section is about. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN style="FONT-SIZE: 130%"&gt;Getting Down to the Wire&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;The ultimate way to debug Silverlight service consumption issues is by using an “HTTP spying” tool such as &lt;A href="http://www.fiddlertool.com/fiddler/" mce_href="http://www.fiddlertool.com/fiddler/"&gt;http://www.fiddlertool.com/fiddler/&lt;/A&gt; or &lt;A href="http://projects.nikhilk.net/webdevhelper/" mce_href="http://projects.nikhilk.net/webdevhelper/"&gt;http://projects.nikhilk.net/webdevhelper/&lt;/A&gt; that shows you the actual HTTP traffic as it happens. Before using it, make sure to enable server-side exceptions (see above). Start your Silverlight app and your tool side-by-side, and make your app do a web service call. Here are some common patterns you will see: &lt;/P&gt;
&lt;P&gt;&lt;U&gt;1.Nothing&lt;/U&gt; &lt;BR&gt;- Your HTTP spying tool may be misconfigured (try running another, non-Silverlight app, like a regular web browser, to make sure it works) &lt;BR&gt;- Your app may be broken – put a breakpoint where you invoke the service, make sure it’s hit &lt;BR&gt;- You may have a configuration issue – see Configuration section above &lt;BR&gt;- You may be trying to host your application from a &lt;STRONG&gt;file:// &lt;/STRONG&gt;or &lt;STRONG&gt;https:// &lt;/STRONG&gt;URL, or trying to call an &lt;STRONG&gt;https:// &lt;/STRONG&gt;service &lt;/P&gt;
&lt;P&gt;&lt;U&gt;2. Just a service request &lt;BR&gt;&lt;/U&gt;- Congratulations – you’ve avoided a cross-domain situation if you see the actual request to the service on the wire. &lt;BR&gt;- Is the address what you expected it to be? &lt;BR&gt;- Look at what’s coming back. Is it timing out or are you getting a 404? Your service or even WCF itself may not be set up correctly. &lt;BR&gt;- Are you getting a SOAP fault back? If so, read carefully what’s in the fault – it will usually have enough information to debug the issue. &lt;BR&gt;- In general, look very carefully at both the request and the reply (including the body and HTTP headers) &lt;BR&gt;- Did you remove anything to get the proxy to compile? The service may actually require some items that you removed (e.g. may require certain SOAP headers) &lt;/P&gt;
&lt;P&gt;&lt;U&gt;3. A request to &lt;STRONG&gt;&lt;EM&gt;clientaccesspolicy.xml &lt;/EM&gt;&lt;/STRONG&gt;(and possibly &lt;STRONG&gt;&lt;EM&gt;crossdomain.xml &lt;/EM&gt;&lt;/STRONG&gt;afterwards), followed by a request to the service&lt;/U&gt; &lt;BR&gt;- Congratulations – you have a cross-domain situation but you have successfully set up your cross-domain policy files &lt;BR&gt;- This is now equivalent to situation #2 above &lt;/P&gt;
&lt;P&gt;&lt;U&gt;4. Just a request to &lt;STRONG&gt;&lt;EM&gt;clientaccesspolicy.xml &lt;/EM&gt;&lt;/STRONG&gt;and nothing else&lt;/U&gt; &lt;BR&gt;- Most likely a malformed &lt;STRONG&gt;&lt;EM&gt;clientaccesspolicy.xml&lt;/EM&gt;&lt;/STRONG&gt;, or one that contains a policy that forbids cross-domain access &lt;/P&gt;
&lt;P&gt;&lt;U&gt;5. A request to &lt;STRONG&gt;&lt;EM&gt;clientaccesspolicy.xml&lt;/EM&gt;&lt;/STRONG&gt;, then &lt;STRONG&gt;&lt;EM&gt;crossdomain.xml&lt;/EM&gt;&lt;/STRONG&gt;, then nothing else&lt;/U&gt; &lt;BR&gt;- Basically, something went wrong with cross-domain policy files. &lt;BR&gt;- Are you getting 404s back? Check if you’re hosting the files correctly and at the correct locations &lt;BR&gt;- Are you getting the actual files back? They may be malformed or may forbid cross-domain access &lt;/P&gt;
&lt;P&gt;&amp;nbsp;-- Eugene Osovetsky, Program Manager, Silverlight Web Services team&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8399338" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/silverlightws/archive/tags/wcf/default.aspx">wcf</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/crossdomain/default.aspx">crossdomain</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/debugging/default.aspx">debugging</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/soap/default.aspx">soap</category></item><item><title>Nice overview of Silverlight HTTP stack</title><link>http://blogs.msdn.com/silverlightws/archive/2008/04/09/nice-overview-of-silverlight-http-stack.aspx</link><pubDate>Thu, 10 Apr 2008 04:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8373736</guid><dc:creator>SLWSTeam</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/silverlightws/comments/8373736.aspx</comments><wfw:commentRss>http://blogs.msdn.com/silverlightws/commentrss.aspx?PostID=8373736</wfw:commentRss><description>&lt;P&gt;Karen Corby, PM working on the Silverlight 2&amp;nbsp;HTTP stack, posts an awesome overview. Her first post covers the site-of-origin policy (also known as the cross-domain restriction) and the two APIs used for HTTP communication: WebClient and HttpWebRequest/HttpWebResponse.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://scorbs.com/2008/04/05/silverlight-http-networking-stack-part-1-site-of-origin-communication/"&gt;http://scorbs.com/2008/04/05/silverlight-http-networking-stack-part-1-site-of-origin-communication/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Yavor Georgiev&lt;BR&gt;Program Manager&lt;BR&gt;Connected Framework&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8373736" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/silverlightws/archive/tags/crossdomain/default.aspx">crossdomain</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/http/default.aspx">http</category></item><item><title>Some tips on cross-domain calls</title><link>http://blogs.msdn.com/silverlightws/archive/2008/03/30/some-tips-on-cross-domain-calls.aspx</link><pubDate>Mon, 31 Mar 2008 03:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8344874</guid><dc:creator>SLWSTeam</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/silverlightws/comments/8344874.aspx</comments><wfw:commentRss>http://blogs.msdn.com/silverlightws/commentrss.aspx?PostID=8344874</wfw:commentRss><description>&lt;P&gt;Recently I have been seeing forum questions on silverlight.net, where people are having trouble with the Silverlight's treatment of cross-domain calls. I wanted go over the cross-domain restriction and share two tips that might help when using cross-domain web services in Visual Studio.&lt;/P&gt;
&lt;H4&gt;What is this cross-domain thing?&lt;/H4&gt;
&lt;P mce_keep="true"&gt;Modern web browsers have restrictions in place to guard against &lt;A class="" title="Cross-Site Scripting (XSS)" href="http://en.wikipedia.org/wiki/Cross-site_scripting" mce_href="http://en.wikipedia.org/wiki/Cross-site_scripting"&gt;Cross-Site Scripting (XSS)&lt;/A&gt; and &lt;A class="" title="Cross-Site Request Forgery (XSRF)" href="http://en.wikipedia.org/wiki/Cross-site_request_forgery" mce_href="http://en.wikipedia.org/wiki/Cross-site_request_forgery"&gt;Cross-Site Request Forgery (XSRF)&lt;/A&gt; vulnerabilities. Exploits of these vulnerabilities&amp;nbsp;can (a) send confidential user data to&amp;nbsp;malicious third-parties or (b) access websites on behalf of the user without the user ever knowing. The example we like to give goes something like this: Sally has an account with Bank XYZ and she uses online banking at &lt;A href="http://bankxyz.com/"&gt;http://bankxyz.com/&lt;/A&gt;. The &lt;A href="http://bankxyz.com/"&gt;http://bankxyz.com/&lt;/A&gt; website stores Sally's credentials in a cookie on her machine as a convenience, so Sally doesn't have to authenticate every time. Tom finds out that Sally uses Bank XYZ, and creates &lt;A href="http://maliciousgame.com/"&gt;http://maliciousgame.com/&lt;/A&gt;, which he sends to Sally. When Sally opens up &lt;A href="http://maliciousgame.com/"&gt;http://maliciousgame.com/&lt;/A&gt;&amp;nbsp;in her browser, a script hosted at the site secretly accesses &lt;A href="http://bankxyz.com/"&gt;http://bankxyz.com/&lt;/A&gt; and transfers money to Tom's account, without Sally finding out. Sally is already authenticated at &lt;A href="http://bankxyz.com/"&gt;http://bankxyz.com/&lt;/A&gt;, so the script can carry out the transaction without Sally's permission. The domain names above are meant to be&amp;nbsp;fictitious... I'm happy to change them if a real "Bank XYZ" or a legitimate "malicious game" come around :)&lt;/P&gt;
&lt;P mce_keep="true"&gt;The most common way to request data is by using JavaScript's &lt;A class="" title="XMLHttpRequest description" href="http://en.wikipedia.org/wiki/XMLHttpRequest" mce_href="http://en.wikipedia.org/wiki/XMLHttpRequest"&gt;XMLHttpRequest &lt;/A&gt;object. To prevent the exploits listed above, browsers implement a&amp;nbsp;&lt;A class="" title="Same origin policy" href="http://en.wikipedia.org/wiki/Same_origin_policy" mce_href="http://en.wikipedia.org/wiki/Same_origin_policy"&gt;site-of-origin restriction&lt;/A&gt;, which doesn't allow websites to make requests outside their own domain.&lt;/P&gt;
&lt;P mce_keep="true"&gt;As a browser plug-in Silverlight also needs to be mindful of these vulnerabilities. We maintain consistent behavior with the browser when it comes to cross-domain calls, and we enforce the site-of-origin restriction across all Silverlight HTTP calls. This applies to &lt;A class="" title=WebClient href="http://msdn2.microsoft.com/en-us/library/system.net.webclient(VS.95).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.net.webclient(VS.95).aspx"&gt;WebClient&lt;/A&gt;, &lt;A class="" title=HttpWebRequest href="http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest(VS.95).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest(VS.95).aspx"&gt;HttpWebRequest&lt;/A&gt;, and the calls made by &lt;A class="" title=ClientBase href="http://msdn2.microsoft.com/en-us/library/ms576141(VS.95).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms576141(VS.95).aspx"&gt;web service proxies&lt;/A&gt;&amp;nbsp;(which use HttpWebRequest internally).&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now this is a bummer for mashups, which are all about pulling data from different web services (Flickr, Yahoo!, Ebay, Facebook, etc) hosted on different domains. So similarly to Adobe Flash, we provide a mechanism to allow cross-domain calls, &lt;A class="" title="How to: Make a Service Available Across Domain Boundaries" href="http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx"&gt;as described in our docs&lt;/A&gt;. By placing a clientaccesspolicy.xml or crossdomain.xml file at the root of its domain, a web service owner&amp;nbsp;declares "the service is safe to be called by any and all Silverlight controls, and no matter who makes the call, the service won't release or mess up the user's private data". For example, Flickr just serves up images, so it is safe and allows cross-domain calls by having &lt;A href="http://api.flickr.com/crossdomain.xml"&gt;a http://api.flickr.com/crossdomain.xml&lt;/A&gt;&amp;nbsp;file. A bank's website should probably &lt;STRONG&gt;not&lt;/STRONG&gt; have a cross-domain policy file at its root.&lt;/P&gt;
&lt;P mce_keep="true"&gt;There are at least two places when working with web services in Silverlight where you might hit the cross-domain restriction without even knowing it. For the following to make sense, &lt;A class="" title="Download Silverilght" href="http://silverlight.net/GetStarted/" mce_href="http://silverlight.net/GetStarted/"&gt;you must have Visual Studio 2008, the Silverlight 2 Beta 1 SDK, and the Silverlight 2 Beta 1 VS tools installed on your machine&lt;/A&gt;.&lt;/P&gt;
&lt;H4&gt;Don't try network calls from TestPage.html on your hard drive&amp;nbsp;&lt;/H4&gt;
&lt;P&gt;When you create a Silverlight project, Visual Studio gives you the choice of hosting the control (i) in the built-in Visual Studio web server or (ii) on your local file system.&lt;/P&gt;
&lt;P&gt;&lt;IMG title="Use the VS webserver if you want to do network calls" style="WIDTH: 425px; HEIGHT: 354px" height=354 alt="Use the VS webserver if you want to do network calls" src="http://blogs.msdn.com/photos/silverlightws/images/8344985/original.aspx" width=425 mce_src="http://blogs.msdn.com/photos/silverlightws/images/8344985/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;The second choice is good if you are just playing with graphics and layout, but it is definitely the wrong choice if you want to use network calls. All HTTP requests (WebClient, HttpWebRequest, web service proxies) are bound to fail. The exact exception when trying to invoke an operation on a web service is shown below. The exception text itself is not that clear, partly because the Silverlight runtime does not contain the full exception strings. How to get the full exception text when debugging is the subject of a whole different post.&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll but was not handled in user code Additional information: [CrossDomainError]&lt;BR&gt;Arguments:&lt;BR&gt;Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See &lt;A href="http://go.microsoft.com/fwlink/?linkid=106663&amp;amp;Version=2.0.30226.2&amp;amp;File=System.ServiceModel.dll&amp;amp;Key=CrossDomainError"&gt;http://go.microsoft.com/fwlink/?linkid=106663&amp;amp;Version=2.0.30226.2&amp;amp;File=System.ServiceModel.dll&amp;amp;Key=CrossDomainError&lt;/A&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;To be fair, we do show you&amp;nbsp;a warning when you try to debug&amp;nbsp;a project on your local file system that uses a web service proxy:&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG title="VS warns not to use network calls when hosted on file system" style="WIDTH: 468px; HEIGHT: 142px" height=142 alt="VS warns not to use network calls when hosted on file system" src="http://blogs.msdn.com/photos/silverlightws/images/8344987/original.aspx" width=468 mce_src="http://blogs.msdn.com/photos/silverlightws/images/8344987/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;This is why we have the first choice, which will host your Silverlight control in the Visual Studio web server at a domain like &lt;A href="http://localhost:1234/"&gt;http://localhost:1234/&lt;/A&gt; (the port number is randomly assigned). Which brings us to the second tip.&lt;/P&gt;
&lt;H4&gt;Don't try to call services that don't have a cross-domain policy file&lt;/H4&gt;
&lt;P&gt;Once you set up your Silverlight app in Visual Studio, it will be hosted by the built-in web server on a domain similar to &lt;A href="http://localhost:1234/"&gt;http://localhost:1234/&lt;/A&gt;. So here the cross-domain restriction will kick in and only allow you to access web services at the &lt;A href="http://localhost:1234/"&gt;http://localhost:1234/&lt;/A&gt;&amp;nbsp;domain. If you add a web service to your&amp;nbsp;solution, you will&amp;nbsp;be able to access that, since it will also live on &lt;A href="http://localhost:1234/"&gt;http://localhost:1234/&lt;/A&gt;, and the cross-domain restriction is avoided.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG title="Add a web service project to your Silverlight solution" style="WIDTH: 765px; HEIGHT: 413px" height=413 alt="Add a web service project to your Silverlight solution" src="http://blogs.msdn.com/photos/silverlightws/images/8344983/original.aspx" width=765 mce_src="http://blogs.msdn.com/photos/silverlightws/images/8344983/original.aspx"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG title="Selecting WCF service project" style="WIDTH: 630px; HEIGHT: 476px" height=476 alt="Selecting WCF service project" src="http://blogs.msdn.com/photos/silverlightws/images/8344988/original.aspx" width=630 mce_src="http://blogs.msdn.com/photos/silverlightws/images/8344988/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;Once&amp;nbsp;you add the WCF service to your solution, you can generate a proxy by right-clicking the Silverlight project and selecting "Add Service Reference" and then using the "Discover" button.&lt;/P&gt;
&lt;P&gt;Of course you don't always want to use a local web service. Say you want to pull some weather data from Weatherbug (you can read the details of their API usage &lt;A class="" title="Weatherbug API" href="http://weather.weatherbug.com/desktop-weather/api.html" mce_href="http://weather.weatherbug.com/desktop-weather/api.html"&gt;here&lt;/A&gt;). You can still use "Add Service Reference", but you will end up with the situation where your Silverlight control is hosted at &lt;A href="http://localhost:1234/"&gt;http://localhost:1234/&lt;/A&gt;&amp;nbsp;and the weather web service is hosted at &lt;A href="http://yourapicode.api.wxbug.net/"&gt;http://yourApiCode.api.wxbug.net&lt;/A&gt;. This would fail due to the cross-domain restriction, unless Weatherbug specifically opted in by placing a policy file at the root of their domain. Fortunately they do :)&lt;/P&gt;
&lt;P&gt;It is&amp;nbsp;interesting to see Silverlight checking for the policy file, I used &lt;A class="" title=Fiddler href="http://www.fiddlertool.com/fiddler/" mce_href="http://www.fiddlertool.com/fiddler/"&gt;Fiddler&lt;/A&gt; to capture it. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG title="Fiddler shows Silverlight looking for policy file" style="WIDTH: 773px; HEIGHT: 195px" height=195 alt="Fiddler shows Silverlight looking for policy file" src="http://blogs.msdn.com/photos/silverlightws/images/8344986/original.aspx" width=773 mce_src="http://blogs.msdn.com/photos/silverlightws/images/8344986/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;Before it does anything, Silverlight searches for a policy file. First it looks for clientaccesspolicy.xml, doesn't find it, and then it looks for crossdomain.xml, and finds it. The crossdomain.xml policy file content says that Silverlight is allowed to use the service at that domain, so Silverlight proceeds to call the .asmx web service. For details on the policy file format, &lt;A class="" title="How to: Make a Service Available Across Domain Boundaries" href="http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/cc197955(VS.95).aspx"&gt;see this article&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Hope this was helpful!&lt;/P&gt;
&lt;P&gt;Yavor Georgiev&lt;BR&gt;Program Manager&lt;BR&gt;Connected Framework&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8344874" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/silverlightws/archive/tags/crossdomain/default.aspx">crossdomain</category></item><item><title>Cross domain policy files in self-hosted services</title><link>http://blogs.msdn.com/silverlightws/archive/2008/03/07/cross-domain-policy-files-in-self-hosted-services.aspx</link><pubDate>Fri, 07 Mar 2008 21:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8104291</guid><dc:creator>SLWSTeam</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/silverlightws/comments/8104291.aspx</comments><wfw:commentRss>http://blogs.msdn.com/silverlightws/commentrss.aspx?PostID=8104291</wfw:commentRss><description>&lt;P&gt;One interesting question from the WCF forums: how to enable the cross-domain calls to self-hosted services, if there isn't an "easy" place to put the clientaccesspolicy.xml (or crossdomain.xml) as there is on IIS? The post at &lt;A href="http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx" mce_href="http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx"&gt;http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx&lt;/A&gt;&amp;nbsp;explains how to use the web programming model capabilities of WCF (.NetFX 3.5) to do that.&lt;/P&gt;
&lt;P&gt;Carlos Figueira&lt;BR&gt;Software Design Engineer in Test&lt;BR&gt;Connected Framework Team&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8104291" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/silverlightws/archive/tags/wcf/default.aspx">wcf</category><category domain="http://blogs.msdn.com/silverlightws/archive/tags/crossdomain/default.aspx">crossdomain</category></item></channel></rss>