RIA Authentication from a Web Services project - silverlight

I have a silverlight app using RIA services. I want to reuse the RIA services component and call it from another web service. The web service and the RIA services component will be on the same server.
I have got quite far along, my web service project has a 'service reference' to the RIA services project which is all good. But when I call one of the RIA services methods I get the exception,
{DDB20766-F78A-42c7-B777-5ECF0AD9E4F3}Access to operation 'GetValidId' was denied.
at System.ServiceModel.DomainServices.Server.DomainService.ValidateMethodPermissions(DomainOperationEntry domainOperationEntry, Object entity)
The RIA services domain class has the attribute [RequiresAuthentication]. I am trying to understand how I can specify those credentials and authenticate?
Just as a test I commented out the attribute [RequiresAuthentication] and everything worked without any problems.

Check out this link:
http://www.ben-morris.com/using-the-wcf-authentication-service-without-cookies
Basically, you have to first successfully authenticate against your server, and have the server send back to you an authentication cookie that you can programatically add to subsequent requests to WCF RIA methods with [RequiresAuthentication] turned on.
Note, to get this to work, in your client program, when setting up WCF bindings to call your server WCF RIA methods, ensure allowCookies="false"; this will allow the code from the above link to actually be able to manually set the cookies in the header.

Related

WCF client hosted in a windows service with a WPF UI

I have now a WCF service that is hosted inside a WPF application. It's running in a WCF server-client scenario where the client can call the server as well (duplex communications).
I would like to host the WCF client in a windows service, but I'd like to keep the WPF UI because of the functionality it provides when making calls back to the server (e.g. request information). I know that windows services don't have UI, but in this case I need it.
What best way is there to communicate between the WPF application and the windows service? (something better than sockets maybe?)
A scenario where this is useful would be something like:
from the WPF application I can choose what kind of information would be required from the WCF service acting as server,
this "command" would be sent to the windows service hosting the WCF client instance, and
using the the instance making the call to the server and
displaying the information in the WPF application via the WCF client service hosted by the windows service.
Thanks,
Adrian
Since the service is already running as WCF, how about exposing some extra "admin" methods on the WCF interface and have the WPF application interact with the service through those?
You'd have to put in a security layer to make sure only the legitimate user could call those new methods, but this solution might be the least work since the WCF infrastructure is already in place.

Generate a WCF proxy for Silverlight without adding the ASync pattern to the WCF service without hosting the service

I got a coding scenario I can't seem to fix.
I got a synchronous WCF service and I want to simulate the Add Service Reference (slsvcutil.exe) but without hosting the WCF service. Is this possible?
I want use slsvcutil to generate the client from a wsdl file but it doesn't want to work because it needs an endpoint. Is it possible to generate a WCF proxy for Silverlight without hosting the service and without editting the WCF service by making all calls Asynchronous?
Is the reason you want to generate the proxies without hosting because you don't want to "add the asynch pattern"?
You don't have to edit the WCF service to make it callable asynchronusly, the asynch is all handled by the client not the server.
Take a look at this tutorial and you'll see that the service code doesn't mention asynch at all. http://www.dotnetcurry.com/ShowArticle.aspx?ID=228
Practically everything in Silverlight is asynchronus and for good reason. It's that way so that the end user doesn't experience blocked UI threads while the app goes off to fetch data.

Custom hosting and "Silverlight-enabled WCF service"

I'd like my WP7 to be able to talk to a service on my local computer. For various reasons it would be more convenient if this service was hosted in a custom host, i.e. an app running locally. However, if I understand correctly "Silverlight-enabled WCF service" need asp.net compatibility, therefore must be hosted in IIS, is this correct?
If so, is there anyway to work round this and get a "Silverlight-enabled WCF service" running in a custom host?
The Silverlight-enabled WCF Service is just a simplified item template from a regular WCF service. It was originally added because the default binding for WCF services wasn't supported in Silverlight, and caused a lot of angst for new Silverlight developers. You should be able to use the regular WCF item in a regular project (e.g. console app) and you'll just have to adjust the bindings.
(Also of note is that the Silverlight-enabled WCF template uses a single code file instead of separating out the service interface from the class implementation.)

Silverlight: Use of a local WCF service for business logic (intermediate WCF Service)? (Ria services in conjunction with a normal WCF Service?)

I have my silverlight calling my WCF service and its working great. This is a WCF (not ria) service that basically returns enitites or collection of entities.
I really don't have control over it to add additional items just for silverlight for example.
So i was thinking but maybe its bad performance or desgin..
But to have a local WCF Service hosted with the Asp.net website that hosts silverlight.. ANd i can use this wcf service for business logic that doesn't need to return entities. For example so silverlight can call to the server and then the server can do something with PURE .net.
Of course i still will need my silverlight to talk to my External WCF service that returns entities etc..
What would be the best way to implement this, if at all..
Silverlight calls local WCF service and "IF REQUIRED" local wcf service calls external WCF Service (which returns entities etc) and everything is returned back down the chain.
or Silverlight calls to local WCF service or to external WCF service depending on what is required.
There is a 3rd option but i am thinking aloud and maybe it wouldn't fit... But to have RIA services so silverlight could call this .... but again I CANNOT get rid of or have control over my other wcf service... So silverlight would need to call both OR ria services could call the wcf service ... But this is where i have a doubt... because RIA services normally return IQUERYABLE for example... My wcf service returns ILIST for example so if ria services called to my wcf service it would receive back an ILIST .. hence the [QUERY] attribute in ria services require me to return IQUERYABLE but it isn't possible because i am already in an ILIST.
I would really appreciate some feedback to weather i am completely missing the point or infact its a good idea.
The fact remains that silverlight sometimes needs to do standard stuff on the server but has nothing to do with dataaccess or entities... i have no control over the external wcf service so i can't just insert a new method specifically for silverlight when its needed..
Anybody use a similar system, PROS / CONS??
Thanks in advance
I think your application should use only Ria Services and then Ria service should connect to the external service. Then all logic is on the server and your SL app has simple model of using services. You can think about is as all business logic is on the server.
What about returning IQueryable you always can "convert" list to IQueryable using linq, but I think you can return list from RIA Service - it shoudn't be a problem.

Is it reasonable to have both DomianService and Silverlight-enabled WCF Service

At the moment it seems that a RIA Domain Services class can not return a sinlge custom type.
There are parts of my app that needs just that, so think the only way to get that is to call back to a simple silverlight-enabled WCF Service, which i beleive will not have a problem returning a custom type. I don't see where the Silverlight client app has any sort of reference to the Ria Services. How do I set up both a Ria services and WCF service on the silverlight client. Will the WCF service be "aware" of the authenication already in place with the RIA services?
This is one of my biggest bugbears of RIA Services :). The good thing is that they are in the process of enabling complex types to be returned from invoke methods (according to the user voice site for RIA Services). However, that won't help you now :).
The best way to implement your requirement to return complex objects is indeed to set up a standard WCF Service to return complex types when required. You do so in the normal way that you would expose a WCF in any web project. You then consume it in your Silverlight application in much the same way you would a WCF Service in any other type of project (by adding it as a service reference). The main difference when consuming it (compared to other types of projects) is that Silverlight only supports asynchronous calls. One difference to be aware of from RIA Services is that whereas RIA Services automatically determines the URI of the domain services (based upon where the XAP file originated from), you will need to handle that aspect yourself (very important when you try to deploy your application :). Do this either by setting the URI in the app.config file, or use the method I use in the code accompanying this article here: http://www.silverlightshow.net/items/Building-a-Framework-for-Silverlight-Line-Of-Business-Applications.aspx.
In regards to your final question, yes, RIA Services uses standard ASP.NET authentication, so the cookie that it uses to maintain your authentication status is also used by any WCF Services in the same project. I talk a bit about security with WCF Services in this article if you want more information: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-3.aspx.
Hope this helps...
Chris

Resources