WCF and Xamarin Forms in the same Visual Studio Project

I am trying to use Xamarin to create an Android app. I really like the Xamarin Forms interface, but it only seems to be available in a Shared Project or a PCL Project. In these, you can't use Windows transport security to connect to a WCF DataService. I can connect to my service fine in and Android targeted app, but the Xamarin Forms are not available there. I am using the evaluation version of Xamarin. I am planning on buying it, but every time I think it can do what I need, it won't quite do it. The only real target I need for this project is Android. I would really like to be able to use the Xamarin Forms and be able to populate them with data from a WCF DataService with Windows Transport Security. Is there a way to do this?

Posts

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    Yes, the WCF code would be platform specific. Within a PCL you can use an interface and IoC such as the dependency service to call into implementations in the platform specific projects that contains the WCF code.

    With shared projects you can use the platform specific code inline, code in there gets whatever references the project that reference the shared project gets.

  • JimWilcoxJimWilcox USMember ✭✭

    @KevinFord Thanks for your reply. Can you call code in the Android Project from a Shared Project? I thought it just went one way from the Shared to the Android or other platform specific.

    I am not familiar with Dependency Services so I will check into those as well.

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    The shared projects are just containers for file linking. It is like the files in the shared project are directly in the projects that reference them. For example if you reference a shared project from an android project you can suddenly start referencing all the android stuff, or a custom class in the Android project. It is like they are all part of the same project.

    Be careful though, the code in the shared projects has to compile in all the projects that reference it. So if you reference a custom class in one platform specific project from a class in the shared project, a class with the same signature needs to exist in all the projects that reference the shared project.

    If you want to see what's happening in a file in the shared project you can open it and in the upper left there is a drop down where you can switch between the different projects that reference the shared project. That way you can see how the code looks in each platform project.

    If you need the code to be slightly different by platform you can use the #if directive.

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    BTW, didn't mean to say WCF up there, should have been PCL. Obviously trying to do too many things at once. :)

  • JimWilcoxJimWilcox USMember ✭✭

    @KevinFord Thanks so much for your help. You have given me new areas to explore in creating my app. My main goal is simply to create an Android only app that uses Xamarin Forms and will let me use WCF with Windows Transport Security. The Android app will do everything except the Xamarin Forms. The PCL will do everything except the WCF. I tried adding a Shared Project to my project last night and all of the WCF code worked fine. What seemed to be missing was the Xamarin Forms. I am going to try creating a Universal App and see if maybe doing it that way will allowed the Shared Project to use the Xamarin Forms.

    The reason I want to use the Xamarin Forms is for the Data Binding capabilities. I did notice, however, that there doesn't seem to be a designer for the Xamarin Forms. There is a designer for the Android Layouts. If I can figure an easy way to databind the textboxes in the Android app, I might just go with the for screen design simplicity. I really like working with XAML and Code behind. The production apps we are using now run on Windows RT and I have gotten used to writing the XAML and Code Behind.

    Thanks again Kevin. This has been a very frustrating transition for me.

Sign In or Register to comment.