Forum Xamarin Cross Platform with Xamarin

Cross Platform consumption of a web service?

JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai
edited October 2013 in Cross Platform with Xamarin

Currently I am using the "Add Web Reference" option in my projects to add a .NET 2.0 web service reference. This is nice and easy and generates the proxy classes just fine. However, I am running into issues now getting this to work cross platform because shared code cannot reference the Web Reference from two (android and iOS) libraries. The situation is the same linking the shared files into the application specific project, or using a library project for each. e.g:

// Shared code file DataAccess.cs

using MyService.Android.DataAccess;
// using MyService.iOS.DataAccess;


public void CallSomething()
    myService.Method(parameter); // Fine for when on android, but now iOS project wont compile because of the namespace issues. 

What are some ways to access my web service in a cross platform way? I would prefer to not have any options that require the service to change technologies. Any examples and suggestions are greatly appreciated!

Thanks in advance!


  • SKallSKall USMember ✭✭✭✭

    Is there a reason you generated the service into different namespaces?

  • WilleWille DEMember ✭✭
    edited October 2013

    @SKall generating the Web Reference twice is not really nice, since you have to change both references once you change your service.

    I did following:
    1 myProject.core containing the originally Web-Reference (this is a Andorid-project)
    2 myProject.core.Android that links to all files in the core. (I created a folder "Web Reference" with subfolder "my_reference" and Linked them to the 3 files that were generated in the myProject.core/Web Reference/my_reference
    3 myPorject.core.iOS (the same as with myProject.core.Android, only that this is a iOS project)
    4 Andorid-App referencing the Android core
    5 IOS-App referencing the IOS core

    In this way you only have to change the Web Reference in your core-project and due to linking the changes apply to the other two cores.
    In this way, I was able to use the Web Reference from the myProject.core in the IOS-App. It´s kinda weired and tricky, and I had to try some things untill I got it to work.

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai


    I didn't choose the namespaces. When I generate the files via "Add Web Reference" in an Android Library Project, it creates the namespace of that project. I can't reference that Library Proj for iOS, so there is a separate iOS Library Project that has to reference the Web Service again via "Add Web Reference", hence the two different namespaces. Maybe I went about creating them incorrectly, any suggestions on how to do it differently?


    Thanks for your reply. I might have to set up something like that if I can't get my solution structure to work.

  • SKallSKall USMember ✭✭✭✭

    If you have a project called MyService for Android and iOS, change the default namespace from MyService.iOS to just MyService, and the same for Android. The project name can have .iOS and .Android extensions if they are in the same folder but I don't really see a need to have them in the namespaces.

  • erivandonserivandons Member
    edited March 2018

    I recently had to implement a cross-platform application consuming webservice asmx.

    My solution was to consume the web service in both projects (Android and IOS).
    In the shared project I used:

        #if __ANDROID__
        using "namespace droid webservice";
        #if __IOS__
        using "namespace ios webservice";

    In the code it was enough to create a new instance of the webservice.

    Worked perfect.

    I hope to help.

Sign In or Register to comment.