[英]How to use same class library on WCF and Silverlight application
Hi I would like to use the same class library from my Silverlight application and WCF based service. 嗨,我想从我的Silverlight应用程序和基于WCF的服务中使用相同的类库。 I created a Silverlight C# class library and found the WCF service does not allow adding reference to Silverlight Project types.
我创建了一个Silverlight C#类库,发现WCF服务不允许添加对Silverlight项目类型的引用。 So
所以
What should i do to make this work? 我应该怎么做才能使这项工作?
Can Silverlight invoke methods on Silverlight Class library if it communicates with WCF service? 如果Silverlight类库与WCF服务通信,它是否可以调用Silverlight类库上的方法?
Is silverlight always this hard? 银光一直都很难吗?
Portable Class Library 便携式类库
http://msdn.microsoft.com/en-us/library/gg597391.aspx http://msdn.microsoft.com/en-us/library/gg597391.aspx
Try making 2 class libraries, one for Silverlight and one for WCF. 尝试制作2个类库,一个用于Silverlight,一个用于WCF。 Both use the same C# source code files.
两者都使用相同的C#源代码文件。 In the second project, you can add the files as link (In Visual Studio in solution explorer: add existing item, and then in the drop-down Add button, choose "Add as link".
在第二个项目中,您可以将文件添加为链接(在解决方案资源管理器中的Visual Studio中:添加现有项目,然后在下拉添加按钮中选择“添加为链接”)。
That's how we solved it for shared code. 这就是我们为共享代码解决它的方式。 You have to limit yourself to library calls that exist in both worlds though.
您必须限制自己在两个世界中存在的库调用。
Now it is easy :D - just use the .shared
trick. 现在很简单:D - 只使用
.shared
技巧。 It allows you to share the same code between server and client. 它允许您在服务器和客户端之间共享相同的代码。 Look here: http://msdn.microsoft.com/en-us/library/ee707371(v=vs.91).aspx
看这里: http : //msdn.microsoft.com/en-us/library/ee707371(v = vs.91).aspx
PS.: You can even add conditional directives on your .shared classes, like this: PS。:您甚至可以在.shared类上添加条件指令,如下所示:
#if SILVERLIGHT
MessageBox.Show("yay, I will run only on silverlight");
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.