1
votes

I am trying to port over our existing ServiceStack DTO service model project to a Portable Class Library, and finding that the RequiredPermission and RequiresAnyPermission ServiceStack attributes don't appear to be defined in the PCL libs from nuget.

I can't find any reference to these attributes in the HelloMobile sample project (https://github.com/ServiceStackApps/HelloMobile/tree/master/src/ServiceModel) whose recent commit comments imply it should be possible to share service DTO definitions between client and server in a PCL service model project.

This is the content of my packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="ServiceStack.Client" version="4.0.52" targetFramework="portable45-net45+win8" />
  <package id="ServiceStack.Interfaces" version="4.0.52" targetFramework="portable45-net45+win8" />
  <package id="ServiceStack.Interfaces.Pcl" version="4.0.24" targetFramework="portable45-net45+win8" />
  <package id="ServiceStack.Text" version="4.0.52" targetFramework="portable45-net45+win8" />
</packages>

I had to add the ServiceStack.Interfaces.Pcl package in order to get IReturn<> attribute which we also make extensive use of.

Any ideas if and where these attributes might be defined for a PCL project?

1
Thanks to mythz for setting us straight on that. For anyone else on this path, and for the avoidance of doubt, the nuget package to go for in a service model project is ServiceStack.Interfaces at linkTomg

1 Answers

0
votes

Filter Attributes like [RequiredPermission] and [RequiredAnyPermission] contain server behavior that doesn't exist on the client.

Since they're an internal implementation detail and not metadata about your Service, it's strongly recommended to avoid annotating them on DTO's entirely and instead add them to your Service Implementation at the "Service-level" which will apply to all Services:

[RequiredPermission("ThePermission")]
public class MyProtectedServices : Service
{
}

Or at the "Action-level" if you only want to apply it to a single Service, e.g:

public class MyProtectedServices : Service
{
    [RequiredPermission("ThePermission")]
    public object Any(ProtectedRequest request)
    {
        ...
    }
}

An alternative solution is to use the C# Add ServiceStack Reference feature which provides another way to get your Services Typed DTO's in a client project with any server-specfic attributes stripped.

DTO's should only depend on ServiceStack.Interfaces

ServiceStack's recommendation is to have all DTO's contained in a separate ServiceModel project whose only dependency is the PCL ServiceStack.Interfaces.dll so they can be re-used by every .NET Client.