开发者

Wrapping a web service around a library

开发者 https://www.devze.com 2023-02-15 11:36 出处:网络
I want to wrap a WCF web service around a client library that accesses a REST API. Currently I\'m just copying the exact method names of the client class as webservice methods and all of the methods l

I want to wrap a WCF web service around a client library that accesses a REST API. Currently I'm just copying the exact method names of the client class as webservice methods and all of the methods look like this

[OperationContract]
pub开发者_开发百科lic <return-type-of-client-method> MethodName ()
{
    return client.MethodName();
}

Is there a way to wrap these calls more efficiently in WCF? I would really not like to have to define 200+ methods like this if there is an easier way to do it.


I don't know if there is "a canonical solution," but if the client library in question is a .NET library you could write a code generator that use reflection to generate the necessary code. Just feed it a list of the library methods you'd like to expose, use reflection to get the return type of the client method and then just spit out that snippet of code for each method in the list.

0

精彩评论

暂无评论...
验证码 换一张
取 消