0

I created a sample webservice that will ask the user for some information and return in JSON form all the information required. I have two issues here

  1. I don't want to make it required that the user enter bot the new dates and renewal dates, I want to make so only one of them is required while the other one is optional
  2. If both dates, new and renewal, are entered then the user will get it all in one JSON but I am not sure how to append both lists together.

Please let me know if you need additional information, here is my code for the webservice

    namespace WebServiceTest
    {
        /// <summary>
        /// Summary description for WebServicePrueba
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class WebServicePrueba : System.Web.Services.WebService
        {
            private string User { get; set; }
            private string UserID { get; set; }
            private DateTime NewServiceDate { get; set; }
            private DateTime NewServicesTo { get; set; }
            private DateTime RenewServiceDate { get; set; }
            private DateTime RenewServiceTo { get; set; }

            [System.Web.Services.WebMethod(Description = "Get Services Received", EnableSession = true)]
            public string getSeviceInformation(string name, string userId, DateTime newServiceDate, DateTime newServicesTo, DateTime renewServiceDate, DateTime renewServiceTo)
            {
                User = name;
                UserID = userId;
                NewServiceDate = newServiceDate;
                NewServicesTo = newServicesTo;
                RenewServiceDate = renewServiceDate;
                RenewServiceTo = renewServiceTo;

                if (User == "prueba" && UserID == "prueba")
                {
                    if (renewServiceDate == DateTime.MinValue || renewServiceTo == DateTime.MinValue)
                    {
                        ArrayList list = this.participant.getAddedTRCTest(newServiceDate, newServicesTo);
                        return JsonConvert.SerializeObject(list);
                    }

                    else if (newServiceDate == DateTime.MinValue || newServicesTo == DateTime.MinValue)
                    {
                        ArrayList list = this.participant.getModifiedTRCTest(renewServiceDate, renewServiceTo);
                        return JsonConvert.SerializeObject(list);
                    }

                    else
                    {
                        ArrayList list = this.participant.getAddedTRCTest(newServiceDate, newServicesTo);
                        ArrayList list2 = this.participant.getModifiedTRCTest(renewServiceDate, renewServiceTo);
                        return JsonConvert.SerializeObject(list);
                    }

                }

                else if (User != "prueba" && UserID == "prueba")
                {
                    return "Please check your username";
                }

                else if (User == "prueba" && UserID != "prueba")
                {
                    return "Please check your UserID";
                }

                else
                {
                    return "Please check both your username and userID";
                }
            }

        }
    }

Here is the error I get when I run the webservice and don't enter one of the dates (i.e I enter newServiceDate and newServicesTo but not renewServiceDate and renewServiceTo or the other way around

    System.ArgumentException: Cannot convert  to System.DateTime.
    Parameter name: type ---> System.FormatException: String was not recognized as a valid DateTime.
       at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
       at System.Convert.ToDateTime(String value, IFormatProvider provider)
       at System.String.System.IConvertible.ToDateTime(IFormatProvider provider)
       at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
       at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
       --- End of inner exception stack trace ---
       at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
       at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
       at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
       at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
       at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
2
Contributors
3
Replies
12
Views
2 Years
Discussion Span
Last Post by pritaeas
0

String was not recognized as a valid DateTime

Can you show the Javascript code you are using to call this webservice?

0

@pritaeas what js code? the whole web service is written on C#.

0

I want to see the code that calls your webservice, Javascript (was my guess), C# or whatever. If I know how the DateTime is sent, I can figure out the problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.