Forum Cross Platform with Xamarin

Exception when using ASMX Web Service e.Result in Xamarin Forms

Hello, I have an ASMX Web Service and an Xamarin Forms Cross Platform application, in the web service i have this:

[WebMethod]
public string SearchBarcode(string FNumber )
{
SqlCommand SqlComman = new SqlCommand();
SqlConnection SqlCon = new SqlConnection();
SqlParameter BARCODE;

        string S =  string.Empty ;
        SqlCon.ConnectionString = "Data Source=192.168.1.100;Initial Catalog=Marketing;User ID=sa;Password=xxxx";
        SqlCon.Open();

        SqlComman.CommandText = " SELECT ITEM_NAME , PRICE1 from BARCODE_VIEW where BARCODE = @BARCODE ";
        SqlComman.Connection = SqlCon;
        SqlComman.CommandType = CommandType.Text;
        SqlComman.CommandTimeout = 0;
        SqlComman.Parameters.Clear();

        BARCODE = SqlComman.Parameters.Add("@BARCODE", SqlDbType.VarChar,50);
        BARCODE.Direction = ParameterDirection.Input;
        BARCODE.Value = FNumber.ToString();

        using (SqlDataReader  BarcodeDataReader = SqlComman.ExecuteReader())
        {
            if (BarcodeDataReader.Read())
            {

                S = BarcodeDataReader.GetValue(0).ToString() + "    " + BarcodeDataReader.GetValue(1).ToString();

            }

            else
                S = "Barcode dose not Exist";

        }

        SqlCon.Close();

        return S;
    }

and in the MainPage.xml i have this code:

public MainPage()
{
InitializeComponent();

        BtnSearch.Clicked += BtnSearch_Clicked;
    }

    private void BtnSearch_Clicked(object sender, EventArgs e)
    {
        ServiceReference1.SumWebSoapClient WS = new ServiceReference1.SumWebSoapClient();


        WS.SearchBarcodeAsync(Convert.ToString(BarcodeEdit.Text));
        WS.SearchBarcodeCompleted += WS_SearchBarcodeCompleted;


    }

private void WS_SummationCompleted(object sender, ServiceReference1.SummationCompletedEventArgs e)
{
Device.BeginInvokeOnMainThread(() =>
{

         Result1.Text = e.Result.ToString();

        });
    }

private void WS_SearchBarcodeCompleted(object sender, ServiceReference1.SearchBarcodeCompletedEventArgs e)
{
Device.BeginInvokeOnMainThread(() =>
{

            Result1.Text =   e.Result.ToString();


        });
    }

I got this exception

Unhandled Exception:

System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. Check InnerException for exception details.

Answers

  • trebor74trebor74 USMember ✭✭

    I couldn't get asmx services to work in the current version. It would be much better/easier to use REST if possible?

  • AboghrisAboghris USMember ✭✭
    @trebor74 yes i think i need to change to REST :( thank u for reply
Sign In or Register to comment.