0

I feel like this should be really simple but I am having an issue figuring out what is going on. I am working with a WCF service and have "Reuse types in all referenced assemblies" on. I have some simple classes to transfer some data. The classes show up fine and all the basic members show up, but no methods do. Are methods not included in this? Do I have to specify this is what I want somehow? Here is some example code. I just switched out my names to make it a little more generic.

public class Car
{
    public string CarColor { get; set; }
    public string Model { get; set; }
    public int Year { get; set; }

    public string GenerateId()
    {
        return CarColor + Model + Year;
    }
}

In this example I get CarColor, Model, and Year on the client side but not GenerateId.

thecaptain0220
  • 2,098
  • 5
  • 30
  • 51
  • do you have a reference in the silverlight project to the library that defines the classes? If yess, then have a look at http://stackoverflow.com/questions/2066343/wcf-service-reference-does-not-reuse-types-in-existing-assemblies-vs-2010-beta – PatFromCanada Jun 09 '14 at 20:53
  • I dont, but maybe this is the route I need to go. I thought that WCF would just pull the classes over. – thecaptain0220 Jun 10 '14 at 15:11
  • nope, It will only reuse the type if it can see it in your Silverlight project. All it can get from the service is the WSDL which describes data not behavior. – PatFromCanada Jun 10 '14 at 15:32

1 Answers1

0

So I ended up doing this a little different. It totally makes sense that only the data comes over. The problem is that I didn't want to have to have a new project to hold the data types. Its just a pain to have a new repository and a completely separate project for a handful of classes. Since I really only need the methods on the client side, I am just creating partial classes with them in it on the client side. That way I can pull the data structure from the service but still extend it to have the methods I need.

Service definition

public class Car
{
    public string CarColor { get; set; }
    public string Model { get; set; }
    public int Year { get; set; }
}

Client partial class

public partial class Car
{
    public string GenerateId()
    {
        return CarColor + Model + Year;
    }
}
thecaptain0220
  • 2,098
  • 5
  • 30
  • 51