Forum Xamarin.Forms

How to solve targetinvokationexception while consuming wcf webservices in xamarin.forms?

PriyaSingh.6224PriyaSingh.6224 INMember ✭✭
edited March 2016 in Xamarin.Forms

I'm consuming WCF soap web services in xamarin.forms. I've added the service reference from the visual studio which generated the asynchronous operations. I've used the following code for consuming the web service

        Service1Client dataCommunicator = new Service1Client();
                                        dataCommunicator.GiveFeedbackCompleted += new EventHandler<GiveFeedbackCompletedEventArgs>(GiveFeedbackCallback);
                                        dataCommunicator.GiveFeedbackAsync(editPhoneF.Text, monuments[pickerMonument.SelectedIndex], editRemarks.Text, imei);
            private async void GiveFeedbackCallback(object sender, GiveFeedbackCompletedEventArgs e)
                        if (e.Result)
                            await DisplayAlert("Success", "Thank you for your valuable comments", "Ok");
                            await DisplayAlert("Oops!!", "Internal server error, please try again later", "Ok");

When I test it on simulator, I just sit and wait for the reply and when I try to use a phone like an android phone then there is an error i.e. targetinvocationexception. What should I do to resolve the issue?

Best Answer


  • Maharshi.5212Maharshi.5212 USMember ✭✭

    Are you using Xaml in your view? Did you use InitializeComponent in your StarterPage xaml.cs or the backend of the starterpage?

  • PriyaSingh.6224PriyaSingh.6224 INMember ✭✭

    Yes I'm using Xaml and there is InitializeComponent() in startpage. The project type is PCL profile 45 #7

  • PriyaSingh.6224PriyaSingh.6224 INMember ✭✭

    I've modified my app and I removed InitializeComponent from main page and also removed the xaml from the starterpage page but still getting the same error.

Sign In or Register to comment.