Connecting MVVMCross Portable connect to WCF DataService. Is it possible?

ぃ、小莉子 提交于 2019-12-11 06:38:19

问题


I need your advice people. I am writing an engineering work project in VS2012 about used car dealership. I have a SQL Database, WCF DataService, WPF application (which is connected succesfuly to WCF) and wanted to create Mobile version for it too. I chose MVVMCross Portable to create Mono For Android and WP7 app with one core. And I have problems here with connecting to my WCF DataService from mobile portable core like:

Unable to add a service reference to the specified OData feed because WCF Data Services is not installed for this target framework. To install a supported version of WCF Data Services, see http://go.microsoft.com/fwlink/?LinkId=253653.

I searched on the internet and it seems that Portable Class Library doesn't support the WCF Data Service yet. I am writing this question to you in hope that there is any solution for this. If not shall I just wait?

  • or perhaps I need to change my WCF Data Service to normal WCF Service that will work on mvvmcross portable but there will be a lot of work to change in app what I have in WPF done,

  • or maybe I should get back to MVVMCross Master, that is without portable-class-library, but there is no support for Android to connect with Data Service.

I read a little about Simply.OData but I have no idea how to put it to work succesfuly.

Thanks in advance.


回答1:


I've connected MvvmCross applications to WCF Basic HTTP data services from all of Droid, Touch and WinPhone (never tried WinRT or WPF - but they should work too)

You are, however, correct that the WCF code will need to be different on the different platforms - this is because the code WCF uses isn't portable.

I think there are 2 basic choices about how to tackle this:

  1. Wrap the WCF code behind a portable interface - an interface that deals in Portable DTO classes and that presents an interface for the Get/Send. You'll then need to write a small class for each platform which maps the portable DTO's to/from the non-portable ones. Tools like AutoMapper may help with this - I haven't tried this on MonoDroid or WinPhone though.

  2. Use file-linking in your core and maintain separate library projects for each platform. For an example of this file linking approach take a look at https://github.com/Redth/WshLst/ - this was for Azure mobile services rather than WCF - but the same principals apply.

Neither of these two approaches is perfect - both put overhead into development - but both still hopefully provide you with a way to share code and build your app moving forwards.

I personally prefer approach 1 - as it provides a clean interface separating the current network stack from my app logic - and it provides me with a technical route to removing WCF and replacing it with something like WebAPI or service stack in the future.


In the near future, there may be a shared Portable Class library profile which supports some WCF functionality across MonoTouch and MonoDroid - but I doubt this will be available at any point soon on Wp or WinRT :/


I'm afraid don't know anything about Simple.OData (this it https://github.com/simplefx/Simple.OData) - I trust the guys who wrote it a lot, but I don't know how well their dynamic code works on WP and MonoDroid. I believe it should work on both - but there may be issues with any code that relies on Reflection.Emit.


One final point - whenever you do anything network related on WP, always try to enable GZip compression if you can - WP doesn't provide this by default.




回答2:


Have a look at Simple.OData.Client. It's a portable class library (used internally but Simple.Data OData adapter) written exactly for this purpose. I even use it with MvvmCross.

It's on GitHub and has a NuGet package. Make sure you install it with "pre" option.



来源:https://stackoverflow.com/questions/14875344/connecting-mvvmcross-portable-connect-to-wcf-dataservice-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!