Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

1. I have a WCF service, deployed as part of an asp.net mvc3 application.

C#
[ServiceContract]
    public interface ILoadService
    {
        [OperationContract]
        string SayHello(string yourName);
    }

// implemented as:
public class LoadService : ILoadService
    {
               public string SayHello(string yourName)
        {
            return "Server Said: Hello  " + yourName;
        }
    }

// The above service is deployed online with basicHttpBinding at some URL.


2. Im using code sharing techniques for Mono For Android, and hence my project setup for android app is as below

a. SharedLibrary : Which adds a Service Reference to the online WCF, and uses it to make calls through a proxy generated through SvcUtil.exe (automatically generated proxy). A file named abc.cs makes the WCF calls

C#
using SharedLibrary.LoadServiceReference;
// WCF Service Added as Service Reference as above line.

using System;
using System.Runtime.Serialization;

public class LoadServiceLibrary
{

    public string SayHello(string yourName)
    {
        using (LoadServiceClient client = new LoadServiceClient())
        {
            var result = client.SayHello(yourName);

            return result;
        }
    }

}




b. SharedLibrary.MonoAndroid : An Android service library that adds abc.cs from SharedLibary "as a link" so that we resolve .net dll issues where SharedLibrary is a common library and SharedLibrary.MonoAndroid uses MonoForAndroid profile.

example: same file above --> as a link

c. I have a project, say AndroidApp, that first adds the SharedLibrary.MonoAndroid as an Existing Project to the solution, adds a reference to the added project. Now the idea is to use Native UI for Android (In future, iOS WP7).

Example Android App:
C#
using SharedLibrary.MonoAndroid; // <<-- Problem
// The above reference will not resolve
// because: SharedLibrary.MonoAndroid in turn references, SharedLibrary
// which contains the WCF reference as using MyWcfService

[Activity(Label = "Second Page")]
public class SecondActivity : Activity
{
    private ProgressDialog progressDialog;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.ServerResponse);

        progressDialog = new ProgressDialog(this) { Indeterminate = true };
        progressDialog.SetTitle("Getting Hello Signal");
        progressDialog.SetMessage("Please wait...");
        progressDialog.Show();

        ThreadPool.QueueUserWorkItem(item => GetResponse());
    }

    private void GetResponse()
    {
        string serverResponse;

        using (LoadService client = new LoadService())
        {
            serverResponse = client.SayHello("My Name");

            if (serverResponse != null)
            {
                RunOnUiThread(() =>
                    {
                        progressDialog.Hide();
      FindViewById<TextView>(Resource.Id.Response).Text = serverResponse;
                    });
            }
        }
    }



Now the problem is... When i add abc.cs as Link to the SharedLibrary.MonoAndroid, the using statement contained in abc.cs (using MyWcfService) in the original project SharedLibrary does not resolve. If i add a new Web Reference, to SharedLibrary.MonoAndroid just to reslove the issue, the whole code sharing breaks down, where in in the future, i might have to add local Reference to SharedLib.iOS, sharedLib.Wp7..

Can anyone suggest a work around for this? because i don't want to break the chain of shared code, which is possible through the original shared library.

Any help is greatly appreciated. Thanks.
Posted
Updated 24-Oct-12 9:50am
v4
Comments
joshrduncan2012 24-Oct-12 15:28pm    
Have you tried contacting Xamarin Support to see if they can help you with this issue?
robroysd 24-Oct-12 15:35pm    
Not yet, since, this is a code sharing issue and not anything perticular to Xamarin. I thought i'd give it a shot here. Maybe someone else has run into this issue before. The thing is, i'm using the technique from Greg Shackle's book and everything works. This is just tricky as there's a WCF reference. Will wait out for other answers. And i'm sure all the examples in Xamarin, depend on local code and not many use WCF. If they do, it's AJAX/REST etc.. not pure normal WCF.
Sergey Alexandrovich Kryukov 24-Oct-12 15:35pm    
I'm afraid to say, you don't have enough information. First, if you do the same in Windows .NET, will it work? Perhaps you need to create an absolutely minimal code sample, test it in different platforms (you can also do it, especially if this is console application sample), report exactly what's going wrong, and, if you still cannot figure out things, post it all here using "Improve question".
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900