共享服务接口和模式在Silverlight中,使用WCF [英] Sharing service interfaces and model in Silverlight, using WCF

查看:146
本文介绍了共享服务接口和模式在Silverlight中,使用WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有,我想我的服务器(一个常规的Web服务)和我的客户(一个Silverlight 2.0的应用程序)之间共享如下界面:

Say I have the following interface that I want to share between my server (a regular web service) and my client (a silverlight 2.0 application):

public interface ICustomerService
{
    Customer GetCustomer(string name);
}

我的Web服务实现了这个接口,并引用客户类型被定义一个类库。

My web service implements this interface, and references a class library where Customer type is defined.

通常情况下,如果你想消费从WCF客户端这项服务,说WinForms应用程序,你可以分享你的模型组装和服务合同的接口。然后,通过使用的ChannelFactory ,您可以动态创建一个实现服务接口的代理。是这样的:

Usually, if you want to consume this service from a WCF client, say a winforms app, you could share your model assembly and your service contract interfaces. Then, by using a ChannelFactory, you can dynamically create a proxy which implements your service interface. Something like:

ICustomerService myService = new ChannelFactory<ICustomerService>(myBinding, myEndpoint);
Customer customer = myService.GetCustomer("romain");

基本上,我想要做同样的事情,但是从一个Silverlight 2.0应用程序。 Silverlight的的ChannelFactory 似乎并不像另外一个...

I basically want to do the same thing, but from a Silverlight 2.0 application. The silverlight ChannelFactory doesn't seems to act like the other one...

你知道这是否是可能的吗?

注:由于Silverlight应用程序只能引用Silverlight的项目,我有:

Note : Since a Silverlight application can only refers Silverlight projects, I have:

两个版本MyModel.dll中包含客户键入

Two versions of MyModel.dll which contains Customer type:

  • 在一个编译目标定位.NET Framework 3.5的,我的web服务项目中引用
  • 在另一个编译目标定位Silverlight的2.0框架,通过我的Silverlight应用程序中引用

两个版本MyServicesContracts.dll中包含 ICustomerService 接口:

Two versions of MyServicesContracts.dll which contains ICustomerService interface:

  • 在一个编译目标定位.NET Framework 3.5的,我的web服务项目中引用
  • 在另一个编译目标定位Silverlight的2.0框架,通过我的Silverlight应用程序中引用

推荐答案

我想你会发现这螺纹有趣。您可以共享不同项目之间code文件编译或对多个目标的单个项目。

I think you will find this thread interesting. You can share code files between separate projects or compile a single project against multiple targets.

这篇关于共享服务接口和模式在Silverlight中,使用WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆