开发者

Asp.Net MVC and WCF - good idea to just call instance methods directly?

开发者 https://www.devze.com 2023-04-13 03:33 出处:网络
I\'m beginning development of a new Asp.Net MVC app. One of the requirements is to expose our API using a webservice - we\'re going to use WCF for this. (We have a third party making an iPhone app tha

I'm beginning development of a new Asp.Net MVC app. One of the requirements is to expose our API using a webservice - we're going to use WCF for this. (We have a third party making an iPhone app that will consume this service)

I'm writing the Asp.Net MVC application that will also consume the WPF API.

I'm thinking that because my MVC ap开发者_StackOverflow社区p will be installed on the same instance of IIS that the WCF app is on, and it will also be part of the same Visual Studio project that I could just call the service methods directly - instead of making calls through the web service.

For example in my controller class I could just do something like

WcfService.SomeClass someServiceClass = new WfcService.SomeClass();
var stuff = someServiceClass.GetSomeStuff()

Is this possible? If so is it wise?


Is this possible?

Yes. You could either import the assembly containing your WCF service contract and implementation into the ASP.NET MVC application and directly call it from there.

If so is it wise?

Yes, you will gain performance this way as you will be short-circuiting the whole serialization/deserialization and network call process.

So if the two are hosted inside the same ASP.NET application you could do it.


Is this possible? 

Sure. Darin is right about this.

Is It wise?

That depends ! Your WCF service can be implemented in multiple ways, for example you can (and maybe should) implement concurrency and instance management other that "per call" - which will work only when service is hosted in WCF capable hosting enviroment and called properly. If you start using it this way

WcfService.SomeClass someServiceClass = new WfcService.SomeClass();
var stuff = someServiceClass.GetSomeStuff()

you are giving up on some very good features WCF offers you to improve scalability and performance. Give it a thought, if it the "serialization-deserialization" overhead is worthy of it. It very well can be !

0

精彩评论

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

关注公众号