简体   繁体   English

通过WCF提供整个库的功能

[英]Provide whole library's functionality via WCF

I want to build a WCF Service application, which is supposed to use a library of mine in order to make all the library's methods available for the service's client. 我想构建一个WCF Service应用程序,该应用程序应该使用我的一个库,以便使该库的所有方法可用于该服务的客户端。 There must be a better way than explicitly writing an OperationContract for each method of my library, which acts as some kind of proxy and calls the library's actual method on the server's side in order to get the returnvalue and deliver it back to the client. 必须有比为我的库的每个方法显式编写一个OperationContract更好的方法,该方法充当某种代理,并在服务器端调用该库的实际方法以获取返回值并将其传递回客户端。

There must be a better way than explicitly writing an OperationContract for each method of my library 必须有比为我的库的每个方法显式编写OperationContract更好的方法

No, not really. 不,不是。

Also remember a library often is stateful, ie you instantiate an object, and when you call instance methods against that object, you preserve state as you saved private members at instance level. 还请记住,库通常是有状态的,即实例化一个对象,并且当您针对该对象调用实例方法时,您将状态保存为实例级别的私有成员。

Only static methods could be 'directly' mapped to service operations. 只有static方法可以“直接”映射到服务操作。

Most probably, you might want to entirely write your WCF contract from scratch to make it service-friendly (ie stateless), and possibly interoperable (faults instead of exceptions...etc.) 最有可能的是,您可能希望完全从头开始编写WCF合同,以使其对服务友好(即无状态),并且可能可互操作(以错误代替异常等)。

If you want access to those methods, you'll need to create operation contracts for them. 如果要访问这些方法,则需要为其创建操作合同。

You can make this easier by creating a small app that loops through the code files, finds and the method signatures, and then formats them for the interface. 您可以通过创建一个小型应用程序来简化此过程,该应用程序循环遍历代码文件,查找结果和方法签名,然后为接口设置格式。 Then you'd just need to copy that code into the interface. 然后,您只需要将该代码复制到界面中即可。

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

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