×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

We were all jumping for joy when Silverlight 2 beta 1 was released and the ability to connect to services was more readily/easily available to us.  For discoverable services that provided a WSDL we were quickly able to implement them using the Add Service Reference capability in Visual Studio 2008.  Beta 2 brings a few changes to the world of services that you should know about.  I’ll do my best to recap some of them here.

Generating a WCF Service

In beta 1 when we created a WCF service for use in Silverlight, we used the “WCF Service” template in Visual Studio (assuming you used Visual Studio).  This was fine and created a standard WCF service for us.  There were a few changes that we had to make to ensure that our Silverlight application could consume it in an acceptable manner.  First, we had to change the binding configuration in ASP.NET web.config from wsHttpBinding to basicHttpBinding as Silverlight only supports that binding type right now.  Secondly, we might have had to add capabilities to enable ASP.NET compatibility support depending on what we were doing with the service.  In beta 2, this process gets a bit simpler for services specifically built for Silverlight.  After you install the tools for Visual Studio, you now get a new item type:

It is important to note that the WCF Service template is still a perfectly acceptable one to choose, you just have to ensure to make those changes accordingly.  The new Silverlight-enabled WCF Service basically does those for us as well as add the ASP.NET compatibility attributes for us in the code.  Additionally, the traditional interface/implementation is simplified into a single class.  Again, the other ways are still valid, but for services specifically built for Silverlight, this might be an easier route to get them done.

Cross-domain policy file updates

Cross-domain restrictions still apply within beta 2 and the same rules apply.  There is one subtle change that is required to your clientaccesspolicy.xml file that is required.  In the allow-from node of the policy file, the attribute http-request-headers is now required.  If your service is an open/public one then specifying “*” is probably acceptable (you’ll have to be the judge of that.  If you only wanted to allow specific headers (besides the blacklisted ones) you can provide those in a comma-separated list and can use wildcards as well.  For example you could use X-MyApp-* if you wanted.

Another thing to note about the support for Adobe’s crossdomain.xml policy file is one thing we found in interpretation of the policy template.  Previously Flash was a Macromedia product and as such that file is adorned with a DOCTYPE that represents a schema with macromedia in it.  Well, Adobe has changed the schema a little bit and also updated the DOCTYPE to reflect Adobe as the authority.  Right now, Silverlight still expects to validate the macromedia declaration.

ServiceReferences.ClientConfig

In beta 1, when you performed the Add Service Reference operation a file named ServiceReferences.ClientConfig was created and had some configuration information in it.  This file, however, wasn’t really used.  In beta 2, this configuration file can be shipped with your XAP and used as configuration.  It provides a subset of WCF configuration.  Refined details of those settings are in the SDK, but I thought it might be helpful to know.

Change to WebClient

In beta 1, WebClient was the easiest library to use in accessing non-discoverable services.  One challenge was that it only supported GET verb requests.  In beta 2 WebClient has changed to enable POST verb actions as well.  the UploadStringAsync function will send the request but the endpoint URI must be a URI that accepts the POST verb.

In addition, WebClient is now callable on a background thread in addition to the UI thread.  This may come in handy for some situations.

I see these as small but helpful changes.  Most are based on feedback we received from beta 1 customers and community, so thank you for that feedback.  I hope this helps!


This work is licensed under a Creative Commons Attribution By license.


6/7/2008 6:06 PM | # re: Silverlight 2 Beta 2 updates for web services
I have not been able to add a service reference to a silverlight application using B2. I used the available WCF tutorial and a video by tim heuer as the methods, as well as trying the new control/wizard. Projects of mine that were able to 'discover' services in B1 are NOT able to in B2.

Any ideas?
6/7/2008 7:48 PM | # re: Silverlight 2 Beta 2 updates for web services
@snelldl: hmm, sounds strange. if you want to email me your projects directly I can try to help. I'm assuming the service project is in the same solution as the silverlight project?
6/8/2008 3:09 AM | # re: Silverlight 2 Beta 2 updates for web services
I upgraded a project from b1 to b2 and the web services stopped working. After 12 hours of banging my head, I decided to go through the quick start tutorial on WCF and also duplicate the technique used in one of your videos, as well as trying the new WCF for Silverlight control/wizard you talked about above. The service page can be seen in a browser from the web side, but you can not 'discover' it in the silverlight project. If you put the full reference in the address box and click go, it will find the service. But when you click OK to add the service reference, it gives the error 'Object reference not set to an instance of an object' and it doesn't add the reference.

I'd be interested to see if you the same problems I did.

6/8/2008 8:09 AM | # re: Silverlight 2 Beta 2 updates for web services
I'm hitting an issue where I can't reference a service that exposes ADO Entities.

The following compiler error in Reference.cs occurs:

Error 1 'System.Runtime.Serialization.DataContractAttribute' does not contain a definition for 'IsReference' ............\Service References\ShopService\Reference.cs

I have posted it at the SL forum here:
http://silverlight.net/forums/p/17546/58427.aspx#58427
6/8/2008 10:29 AM | # re: Silverlight 2 Beta 2 updates for web services
I get the

'Object reference not set to an instance of an object'

problem when trying to add a Service Reference to an asmx service. This always worked with B1

Dave
UK
6/8/2008 4:05 PM | # re: Silverlight 2 Beta 2 updates for web services
I'm having the same problem with adding web service references with SL2B2 w/VS 2008 SP1.
6/8/2008 5:33 PM | # re: Silverlight 2 Beta 2 updates for web services
Had similar problems with web services above. Bata 2 doesn't seem to recoginse the ServiceReferences.ClientConfig file. Got around the problem by instantiating an Endpoint Address and Binding in code and call the web service with these
6/9/2008 3:08 AM | # re: Silverlight 2 Beta 2 updates for web services
I'm having a similar problem. I can't add a reference to a web service (getting the 'Object reference not set to an instance of an object'). In addition, i also get the error when trying to delete an old reference (added in Beta 1)

6/9/2008 4:14 AM | # re: Silverlight 2 Beta 2 updates for web services
Also, i get a "Unable to find service 'DynamicTypeService'. Ensure that the application is installed correctly." when trying to configure the service reference.
6/9/2008 5:27 AM | # re: Silverlight 2 Beta 2 updates for web services
I did this and it fixed my wcf problems:

http://www.itwriting.com/blog/?p=665
6/9/2008 10:12 PM | # re: Silverlight 2 Beta 2 updates for web services
Got bit by the changes in crossdomain.xml and required http-request-headers attribute.

I've noticed alot of sites like:

- http://twitter.com/crossdomain.xml
- http://search.yahooapis.com/crossdomain.xml
- http://api.flickr.com/crossdomain.xml

Don't include this attribute. This is going to cause app breakage (specially the Flickr one)...

6/10/2008 7:19 AM | # re: Silverlight 2 Beta 2 updates for web services
http://www.itwriting.com/blog/?p=665

fixed my WCF woes as well.
6/10/2008 8:53 AM | # re: Silverlight 2 Beta 2 updates for web services
@Jonas: those sites use the Adobe crossdomain.xml format, for which Silverlight supports a specific format (those that are there are fine). The change was to Silverlight's specific policy format (clientaccesspolicy.xml).
6/25/2008 1:10 PM | # re: Silverlight 2 Beta 2 updates for web services
Based above discussion and this post:
http://developer.amazonwebservices.com/connect/thread.jspa?threadID=22583&tstart=0

my understanding is that a SilverLight app cannot talk to Amazon Web Service directly, right? Will Microsoft push Web Service Providers like Amazon to implement ClientAccessPolicy.xml or this might be changed in future release?

Thanks
Kent
6/25/2008 1:36 PM | # re: Silverlight 2 Beta 2 updates for web services
@Kent: we are working with Amazon to see about updating their files.
6/25/2008 3:48 PM | # re: Silverlight 2 Beta 2 updates for web services
Thanks Tim!
7/2/2008 12:47 AM | # re: Silverlight 2 Beta 2 updates for web services
Thank you very much for the informative post. I too was banging my head against the 404 error [even though my tiny webservice was up and running]. It didn't dawn on me that the existence of the policy file was REQUIRED.. duh! :)
7/3/2008 1:01 PM | # re: Silverlight 2 Beta 2 updates for web services
We are offering data through web services. Recently in order to support beta 2 apps, I updated my clientaccesspolicy file to include http-request-headers="*" attribute. But this broke the beta 1 apps that were earlier working fine consuming our web services.

<?xml version="1.0" encoding="utf-8" ?>
- <access-policy>
- <cross-domain-access>
- <policy>
- <allow-from http-request-headers="*">
<domain uri="*" />
</allow-from>
- <grant-to>
<resource path="/" include-subpaths="true" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

Are the policies of beta 1 and beta 2 conflicting? Can they not co-exist? Thanks in advance.
7/3/2008 1:13 PM | # re: Silverlight 2 Beta 2 updates for web services
@vchip: they cannot co-exist no. beta 1 is no longer supported per the EULA
7/4/2008 11:40 AM | # re: Silverlight 2 Beta 2 updates for web services
Seems Amazon still hasn’t implemented clientaccesspolicy.xml. Not sure how long it’ll take before all of those popular sites (amazon, google, facebook etc etc) implement it…
I’m still wondering why we need this file though… I can understand if a silverlight app tries to make a cross domain web service call, user should get a security warning. But why does Amazon need a new file to prevent people from accessing its data? You need to provide your Amazon key/id anyway…
7/5/2008 8:31 PM | # re: Silverlight 2 Beta 2 updates for web services
Tim, thanks for the quick reply.
Gravatar
7/9/2008 9:03 AM | # re: Silverlight 2 Beta 2 updates for web services
A Silverlight sample that works with a WCF self-hosted app is greatly appreciated, especially using an existing MSDN WCF sample.

The examples I found on MSDN are created using the VS "Web Service Application" project template, which creates ASP.Net apps.
7/9/2008 9:05 AM | # re: Silverlight 2 Beta 2 updates for web services
Mel: See http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx
7/16/2008 11:11 PM | # re: Silverlight 2 Beta 2 updates for web services
I've used WCF-for Silverlight template and can see through browser. But
If I try to add a service reference to SL application it does not work.

Basically this web service is behind basic authentication so when I tried to add in vs2008 it has asked for the password but it is not working/ cannot download wsdl.

I can see WSDL through browser by providing same userid and password.

i cannot use the svcutil.exe because i could not find command line switch to provide userid, and password... it is making me crazy.

please help.
8/6/2008 8:53 AM | # re: Silverlight 2 Beta 2 updates for web services
Hi Tim,
I created a WCF Service using Visual Studio 2008. I then tried invoking this service from a Silverlight 2 Beta 2 app within the same solution. I am not able to do so. Both the WCF Service and the Silverlight project are on the same PC. So I shouldn't have any cross domain issues. I get the following error message:

An error occurred while trying to make a request to URI 'http://localhost:3862/Service1.svc'. This could be due to a cross domain configuration error. Please see the inner exception for more details.

I do not know where to go from here. Could you help ?

Thanks,
Sudeep
8/6/2008 1:19 PM | # re: Silverlight 2 Beta 2 updates for web services
Hi Tim,
Thank you very much for the quick responses. After seeing your video that you posted for cross-domain policy problems, I was able to correctly place the clientaccesspolicy.xml file in the right place. Everything has gone on smoothly from there.

Thanks a bunch,
Sudeep
8/13/2008 9:16 AM | # re: Silverlight 2 Beta 2 updates for web services
Hoping you might be able to lend some guidance on some issues I'm having with a WCF service and a silverlight application.

I have a WCF service that is up and running on my local IIS server, http://localhost/Services/MyNewService.svc

The SVC file points to a dll that implements the service functionality and interface IService.cs and Service.cs.

I can open a browser and hit the service no problems. I see the WSDL, I am able to hit the service via console application and fetch the information and display the data.

Having read about cross-domain issues I added a clientaccesspolicy.xml file to the root of my webserver.

I then created a new Silverlight application and added a service reference to the WCF service on my local machine. I am able to see the methods of the service, and add respective event handlers for the completed events.

I am hitting a 404 error on the completed event.

I have used both fiddler and web development helper and am only getting responses of 200.

I have upgraded to VS2008 SP1, 3.5 Framework SP, and reinstalled the SL SDK, and am at a loss for what could be wrong here. If you could lend any guidance that would be greatly appreciated.

Thanks.
8/20/2008 2:02 PM | # re: Silverlight 2 Beta 2 updates for web services
Hi Tim,
Good post, it has helped me to resolve my problem with calling wcf service. Problem was in the http-request-headers attribute and a one stupid typo.
Guys please check whether you are using
This typo cost me 2 hours :).

Thanks.

P.S. (Sorry for my english. It's not my native language)
8/20/2008 2:07 PM | # re: Silverlight 2 Beta 2 updates for web services
It seems html tags are not allowed.
Missed text for previous message:

grant-to
resource path="/" instead of resource path="\"
/grant-to

P.S. (Sorry for my english. It's not my native language)
8/23/2008 5:31 AM | # re: Silverlight 2 Beta 2 updates for web services
Yep this post just fixed 8 hours of trouble shooting for me!
9/8/2008 9:30 PM | # re: Silverlight 2 Beta 2 updates for web services
Hi Tim
I think there's a deployment issue

Silverlight-enabled WCF Service is a usful simplication Thanks
Started to use Web Development Helper Thanks for the tip

When I run ASP.NET Development server
e.g. http://localhost:49459/ Everything Works fine

When I Publish to a real server WCF Sevice no longer works (everything else does).
Suspect it's looking for service localhost:49459 on my local machine
On the remote Server I can see the ClientAccessPolicy.xml in the root folder which is where "Publish" put it.

Note: in Server xap file I can See
http://localhost:49459/CcrService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_CcrService" contract="CcrDev.ProxyCcr.CcrService"
name="BasicHttpBinding_CcrService" />

How do you fix this?

Locally I'm using VS 2008 SP1 (Vista Business), .Net3.5 SP1
Remote Server is MS Server 2008 .Net3.5 SP1
10/7/2008 1:31 PM | # re: Silverlight 2 Beta 2 updates for web services
Tim,

I wanted to post this error here since it is affecting my Silverlight application.

if I create a new SL application, create my web service (or WCF), I can then attach the service reference to my SL application. If I create a new SL application, SAVE IT, then try and do the web services, I get an error:

"There was an error downloading metadata from the address".

This only happens if the project is saved. no matter where you are in the service creation from not started to done, if the solution is saved, you cannot see the service due to the above error.

i am running Vista with all patches and running VS2008 as an Administrator.

Any insight would be appreciated.
10/7/2008 8:30 PM | # re: Silverlight 2 Beta 2 updates for web services
I might add that after getting this error "There was an error downloading metadata from the address", it hard crashes Visual Studio with this error:

.NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (70ED7706) (80131506)

Neither WCF or older web services work. I will use XML config files for now and place them in the application until I can figure out why.

The only file that changed its write time was the solution file which doesn't make sense on the error.
10/7/2008 8:45 PM | # re: Silverlight 2 Beta 2 updates for web services
Alan: this looks like it cannot resolve the service. Have you confirmed the service endpoint is browsable itself? Usually I see this when I'm using VS web dev server and the service isn't spun up yet (also beware of ports changing).
10/8/2008 12:16 PM | # re: Silverlight 2 Beta 2 updates for web services
The endpoint is browsable when I run Cassini. The port checks out for the service with what is being discovered in VS2008.
10/8/2008 12:24 PM | # re: Silverlight 2 Beta 2 updates for web services
Alan: (fyi I tried emailing you offline, but your mail server rejected). Is the binding set to basicHttpBinding on the service? Is there a repro you could send me offline to look at?
10/8/2008 1:48 PM | # re: Silverlight 2 Beta 2 updates for web services
Tim,

Thanks for taking a look. Yes, I am set for basic (I used the new WCF for Silverlight). Not sure why my mail server would have rejected (I control my own domain and do not filter).

You can find the sample here:

cid-8bca55fbca813d37.skydrive.live.com/.../....zip

It does not appear to be code or file related. It works if I create a new app and then do the service immediately. It fails if it is saved and reopened. I suspect a Vista patch but that is a guess.
10/8/2008 9:42 PM | # re: Silverlight 2 Beta 2 updates for web services
Alan: I took a look at your project, opened, removed, re-added, deleted, restarted, closed, re-opened many times and was able to add a service reference each time.

What version of Silverlight are you running and if not the RC0, can you try that? It could be a bug with the data client services in beta 2 that has since been fixed.

I'm sorry, I just can't reproduce it :-(
10/8/2008 9:54 PM | # re: Silverlight 2 Beta 2 updates for web services
Tim,

Understood. It was baffling to me and I spent a lot of time trying to isolate it. I haven't gone to RC0 since I wanted to deploy this on B2. My client wanted something on Oct 15th which is, unfortunately, a week away from RTW (guessing ;-]).

I think I will download RC0 and install it in a virtual machine and give that a go. Not sure where else to turn.

Thanks for giving it a try. This is beta software so I go in with eyes wide open...

If RC0 fixes it then I will look forward to LA announcements. I have a separate conference at the same time so I will miss the soiree...



10/14/2008 9:24 AM | # re: Silverlight 2 Beta 2 updates for web services
SL 2 RTW fixed the issue. I never got around to RC0 but no matter.

Thanks for all of the work on helping the community out and congratulations on the SL2 release.
10/27/2008 5:45 PM | # re: Silverlight 2 Beta 2 updates for web services
I am trying to use a 3rd party web service that has a crossdomain.xml which looks like:


"www.macromedia.com/.../cross-domain-policy.dtd">




It does not have a clientaccesspolicy.xml file. Even though SilverLight finds the crossdomain.xml, I still get the following:

An error occurred while trying to make a request to URI 'http://www.webservicex.net/stockquote.asmx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details.
12/2/2008 3:21 PM | # re: Silverlight 2 Beta 2 updates for web services
Arpit: Have you resolved this issue?
12/6/2008 8:57 PM | # re: Silverlight 2 Beta 2 updates for web services
hi there have enless hassles with error dcom1084 for weeks on end my drives need updating .i surely hpe that with silverlight those problem will fall away am i on the silverpath or still on the wrong pass as i strugle to sort out the problem so why noy go a step ahead so thank you and have a good festive season alberto
12/7/2008 11:57 PM | # re: Silverlight 2 Beta 2 updates for web services
Tim, I am trying to databind as well, it gives me error

throw new Error("Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()\n at TestGrid.ServiceReference1.GetDataCompletedEventArgs.get_Result()\n at TestGrid.Page.webService_GetDataCompleted(Object sender, GetDataCompletedEventArgs e)\n at TestGrid.ServiceReference1.TestServiceClient.OnGetDataCompleted(Object state)");

I can't seem to get testinsync no matter what, I have browse through the site for almost entire day and i just can't seem to find an answer, i have tried both traditional wcf and silverlight-wcf.

If you can provide some help I'd be highly appreciated
12/8/2008 7:57 AM | # re: Silverlight 2 Beta 2 updates for web services
Peter: the error indicates there is an inner exception you should look at. It's hard to say what the issue could be without being in front of it, but I'd use some helper tools like Fiddler or Web Development Helper to investigate the requests and responses.
3/22/2009 1:37 PM | # re: Silverlight 2 Beta 2 updates for web services
Hi Tim,

I have the same issue as Arthur.

How do you resolve this?

Regards
Fredrik
3/22/2009 2:27 PM | # re: Silverlight 2 Beta 2 updates for web services
Frederik -- you have to change the binding to match your new production URI. You can manually do that in the config file by changing the URI (if the service is exactly the same) or you can add a reference to the production URI.
12/28/2009 9:20 PM | # re: Silverlight 2 Beta 2 updates for web services
Hi Tim. Nice post. I'm doing some tests with Silverlight + WCF and I found a big issue. When you are passing an object with circular references from server to SL client it can be resolved being aware about those references in ContractBehavior and applying this as an attribute. But when u try to pass the same complex object from Silverlight to server I wasn't able to do this. Why? B/c i don't have the same classes I used to control my Contract:

CircularReferencesAwareAttribute : Attribute, IContractBehavior, IOperationBehavior
CircularReferencesAwareContractBehavior : IContractBehavior

Any idea? How can I implement that in SL? Thanks in advance.

 
Please add 5 and 6 and type the answer here:

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.