Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

consuming SAP web service from web app part 2

Avatar of CL-IS
CL-ISFlag for United Kingdom of Great Britain and Northern Ireland asked on
4 Comments1 Solution309 ViewsLast Modified:
please refer to "consuming SAP web service from web app part 1".

If i enter a value click submit to go SAP and if the value doesnt exist the my code for the consumed web service falls over and i need to get it to stop doing this, if value doenst exist then it should return nothing and go back to my web form with no data.

Consumed web service code...snippet

        public sap.r3dev.Aufm ZGetMatDocs(string job)
            ConnectionStringSettings wtcn = ConfigurationManager.ConnectionStrings["WTCn"];
            SqlConnection cnn = new SqlConnection(wtcn.ConnectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnn;

            sap.r3dev.service MySAPService = new sap.r3dev.service();
            sap.r3dev.ZGetMatDocs MySAPParameters = new sap.r3dev.ZGetMatDocs();
            sap.r3dev.ZGetMatDocsResponse MySAPResults;
            sap.r3dev.Aufm[] MySAPServiceDetails = new sap.r3dev.Aufm[0];

            System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
            cred.UserName = "TEST";
            cred.Password = "TEST";

            MySAPService.Credentials = cred;

            MySAPParameters.Docyear = "2004";
            MySAPParameters.Movementtype = "261";
            MySAPParameters.Workorder = job;
            MySAPParameters.Details = MySAPServiceDetails;
            MySAPResults = MySAPService.ZGetMatDocs(MySAPParameters);

            int i;
            string Workorder;
            string Docyear;
            string Movementtype;
            string BatchNumber;
            string Quantity;
            string MaterialNumber;
            string errorMessage = "";

            string sql = "INSERT INTO wp4tbl_TblCompVerifySapBatch (Workorder,Docyear,movementtype,BatchNumber,Qty,MaterialNumber) VALUES (@Workorder,@Docyear,@movementtype,@BatchNumber,@Qty,@MaterialNumber)";
            SqlCommand myCommand;

            catch (SqlException SQLex)
                errorMessage = SQLex.Message;
            catch (Exception ex)
                errorMessage = ex.Message;

            myCommand = cnn.CreateCommand();
            myCommand.CommandText = sql;

            for (i = 0; (i <= (MySAPResults.Details.Length - 1)); i++)
                Workorder = MySAPResults.Details i.Aufnr; //removed bracket bcoz EE doesnt like it when trying to submit
                Docyear = MySAPResults.Details i.Mjahr;
                Movementtype = MySAPResults.Details i.Bwart;
                BatchNumber = MySAPResults.Details i.Charg;
                Quantity = Convert.ToString(MySAPResults.Details i.Menge);
                MaterialNumber = MySAPResults.Details i.Matnr;
                myCommand.Parameters.Add(new SqlParameter("@Workorder", Workorder));
                myCommand.Parameters.Add(new SqlParameter("@Docyear", Docyear));
                myCommand.Parameters.Add(new SqlParameter("@movementtype", Movementtype));
                myCommand.Parameters.Add(new SqlParameter("@BatchNumber", BatchNumber));
                myCommand.Parameters.Add(new SqlParameter("@Qty", Quantity));
                myCommand.Parameters.Add(new SqlParameter("@MaterialNumber", MaterialNumber));
            return MySAPResults.Details 0; //IF NO DATA FOR THAT VALUE IT FALL OVER HERE!!!
Avatar of ChetOS82
ChetOS82Flag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers