Parsing incoming DateTime in C# WebService myself?
-
I have a method in my Webservice:
[WebMethod]
public ReturnList GetList(string id, System.DateTime fromDate)If I enter a invalid date when testing the service, I get a custom html-page with the errormessage and a stacktrace. How can I get rid of this? I want to handle the parsing of the incoming date myself, and send back a ReturnList object with a custom errormessage.. But I don't want to use string instead of dateTime, since I want it to be specified as dateTime in the wsdl..
-
I have a method in my Webservice:
[WebMethod]
public ReturnList GetList(string id, System.DateTime fromDate)If I enter a invalid date when testing the service, I get a custom html-page with the errormessage and a stacktrace. How can I get rid of this? I want to handle the parsing of the incoming date myself, and send back a ReturnList object with a custom errormessage.. But I don't want to use string instead of dateTime, since I want it to be specified as dateTime in the wsdl..
What about using an overload that way if it is passed in as something other then a valid DateTime object it will get treated by the overlaoded method and there you can try parsing it manually:
[WebMethod] public ReturnList GetList(string id, string fromDate) { // overlaod // your parsing logic } [WebMethod] public ReturnList GetList(string id, System.DateTime fromDate) { // Original function }
Worth a try ... hth