2
votes

Good day. I try to build Windows And WP7 Applications, using one WCF service. For greater convenience i want to define all my contracts and interfaces in one common library. But, since WP7 project cant reference to Win-library i create a WP7 Class Library and in him i create next class:

[ServiceContract]
    public interface IStubSrv
    {
        [OperationContract]
        void Foo1();
        [OperationContract]
        void Foo2();
}

But i have next problem: when i add reference in Win-Project to this library in runtime i get next exception:

Could not load file or assembly 'System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

If i remove reference to System.ServiceModel from my common library - i can add reference to my library in Win-Project, but i cant use ServiceContract and DataContract attributes, and than CLR cant use this library via WCF.

So my directly question: can i create common library whith definition WCF-contracts, which can be used by WCF-infrastructure, Windows Application and WP7 Application? Or i must create two different assembly with exactly the same code??

1
+1. you saved me from posting a question to SO - Sandy

1 Answers

1
votes

Yes, it is possible to create a library that can be shared directly between WP7 and a Windows Application (I assume yo mean WPF / WinForms?). You can do this by creating a Portable Class Library.

The APIs available to you depend on the platforms you wish to target, for example if you wish to use your portable class library for XBox, the APIs are very restrictive. However for WP7 / WinForms / WPF / ASP.NET you can share quite a bit of code, including WCF client code.