简体   繁体   English

从RIA服务转换为WCF Web服务

[英]Converting from RIA Services to WCF Web Services

What steps must I take to convert from RIA Services to plain WCF Services? 我必须采取哪些步骤才能将RIA服务转换为普通WCF服务?

Notes: 笔记:

  • I have one service with 6 methods 我有一个服务有6种方法
  • I am passing large object back & forth and I want more control over them, so I need to switch to WCF 我来回传递大对象,我想要更多控制它们,所以我需要切换到WCF
  • I am using Silverlight as my primary client 我使用Silverlight作为我的主要客户端

In brief, if you're passing a large object back and forth to the service, then you're probably doing it wrong. 简而言之,如果你将大型对象来回传递给服务,那么你可能做错了。 Just send your object to the server, do all the required processing on the server, and then simply return the result back to the client. 只需将对象发送到服务器,在服务器上执行所有必需的处理,然后只需将结果返回给客户端即可。 Why should you incur the performance and bandwidth costs of transferring the large object back and forth across the wire (over HTTP)? 为什么要通过线路(通过HTTP)来回传输大型对象会产生性能和带宽成本?

Since you're using Silverlight as your primary client, then you will be using Asynchronous calls (which is yet another reason to stick to one call to the service). 由于您使用Silverlight作为主要客户端,因此您将使用异步调用(这是坚持对服务的一次调用的另一个原因)。 There are several ways you can manage instantiating your WCF service: You can either do it the simplest way by adding a reference of the service to your Silverlight client, or you could write some custom client that can execute methods on your service as follows: 有几种方法可以管理实例化WCF服务:您可以通过向Silverlight客户端添加服务引用以最简单的方式执行此操作,也可以编写一些可以在服务上执行方法的自定义客户端,如下所示:

client.ExecuteAsync<IService, TResult>(String methodName, Action<TResult> complete, Action<Exception> failure, params object[] parameters)

Then in your service contracts, you should write both versions of your operations: the synchronous and the asynchronous. 然后在您的服务合同中,您应该编写两个版本的操作:同步和异步。 For that, use a compiler conditional to separate the two: 为此,使用条件编译器将两者分开:

#if(SILVERLIGHT)
[OperationContract(AsyncPattern = true)]
IAsyncResult BeginMyMethod(Int32 value, AsyncCallback callback, Object asyncState);
Double EndMyMethod(IAsyncResult result);

//more operations

#else
[OperationContract]
Double MyMethod(Int32 value);

//rest of the methods

#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM