Xamarin Forms doesn't call Webservices(ASMX) properly

DranakDranak FRMember ✭✭

Hi,

I am french so if my english is a little bit eyesight, sorry.

So I work with Xamarin Forms (the first time) and I have a Webservices ( ASMX).

When I use it whith a .Net application it's work fine even with an asp application, but with Xamarin it was really hard to add it to my project and now when I want to use it with async methods (I only have this one), the result that I get with the complete method is null.

I search a way to pass to it but I didn't find a answer.

The only thing I discover it's when I call my async method (with string parameter) Xamarin send a string with value = "",while my parameter that I send has a value.

ATM I don't have the code with me but I think it's xamarin problem and not in my code proprely

How I can pass out this issue ?

Thank to you. :)

Dranak

Ps: Tell me If you want more details, when I get back the code I give it to you :)

Posts

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Hi,

    Have you gone through the sample and applied your code-steps accordingly for consuming the ASMX services?

    -- N Baua

  • DranakDranak FRMember ✭✭

    Hi,

    At first thanks for your quickly answer.

    I saw the example had you give, maybe I missed something but I think I properly add my webservice to my project because VS know him.(The autocomplete know my webservice methods and everything)

    Also I can connect to it so it's look like It's work.

    For now my webservice it's on localhost maybe it's not working with localHost ?

    Sorry I don't have the code with me so I can't give it but I can give you a schema with my memories . :)

    I create a new Object "webservices" when I need him.

    I call some methods, for example "setQuery(String query)" like this.

        Mywebservice obj = new MyWebservice();
    
    
    
    
        obj.setQueryAsync("Textbox.text");  // textbox.text value is "Select Id From dbo.Absences;"
    
        obj.setQueryComplete += setQueryComplete() ; // Generated by VS 
    
    
    
        //Method generated 
    
        public void setQueryComplete(Object o, Result e) // I don't remenber properly but I think you know this kind of method :)
        {
            e.Result  = do your stuff
        }
    

    I hope my english it's not so bad and I hope it's help you :)

    Dranak

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Hi @Dranak,

    Yeah localhost and 127.0.0.1 with/without port, doesn't seem to work. Rather host your service on local IIS and use the ip address, say for example my services work as http:\\192.168.1.15\gingerco\products.asmx.

    -- N Baua

  • DranakDranak FRMember ✭✭

    Ok I will try this if i can.

    But what is the issues with localhost ? Because i can connect to it ( my database is update ), so i don't understand the issues.

    Thanks again.

    Dranak

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Hi @Dranak ,

    As simple answer as there is no localhost for emulator, its not the Xamarin limitation, it is the architecture, the way it is.
    A simple question 'Can android (or iOS for that matter) possibly know what the localhost mean?', NO because the localhost is a Windows (IIS) paradigm and typically service end-points work with the URIs (so the ip addresses).

    Hope that answers, your concern.

    -- N Baua

  • DranakDranak FRMember ✭✭
    edited October 5

    Hi @N_Baua ,

    Yeah I know if i want to connect to localhost with android device it's not working, maybe with emulator but I didn't find a way to connect my emulator to internet ( proxy issues)...

    So I try to with windows universal app into my project and now I debug with it.

    For me if I launch my "universal windows app " in desktop, he knows localhost, no?

    Sorry to don't tell you this, but as I didn't mentioned android I think it was intuitive.

    Dranak

    Edit:
    This is the code where I use my Webservice I hope it's help you to undersand my issue.

    If you want my all Mainpage I can give you too.

    Also, it's related with webservice and Xamarin so I ask here ^^ but how I convert Sytem.Data.Datable ?
    Because some methods of my Webservice return this object and Xamarin Forms doesn't kwon Sytem.Data ..... (
    for my Webservice works I commented these methods, but I need them)

     private void Button_Clicked(object sender, EventArgs e)
            {
                WebService1SoapClient obj = new WebService1SoapClient();
    
                if (!string.IsNullOrEmpty(textbox.Text))
                {
                    try
                    {
    
                        obj.setQueryCompleted += Obj_setQueryCompleted;
                        obj.setQueryAsync("Select Id From dbo.Absences"); 
                    }
                    catch (Exception ex)
                    {
                        // display error message or whatever
                    }
                }
                else
                {
                    label.TextColor = Color.Orange;
                    label.Text = "Input has no value";
                }
            }
    
            private void Obj_setQueryCompleted(object sender, setQueryCompletedEventArgs e)
            {
                allReadyAdded = e.Result;
    
                if (!allReadyAdded)
                {
                    label.TextColor = Color.Green;
                    label.Text = "Query added";
                }
                else
                {
                    label.TextColor = Color.Red;
                    label.Text = "Query already added";
                }
    
            }
    
Sign In or Register to comment.