I have an InfoPath 2007 form that is all working correctly. It uses a webservice to both retrieve and submit data.
After I added another web method to this service that passes a date (datetime format 8/25/2010) as a parameter, I get the error "The string '' is not a valid AllXsd value".
I have since stripped the web method down to where all I do is to pass the string as a parameter and attempt to return the date as a string so I can see what was sent, but I can't get past the error message. If I pass a datetime field I always get the error. The data connection for the method is on submit but I see the error as soon as the form tries to open.
Is there something special that needs to be done to pass the datetime as a parameter to a web service?
Here is the full text of the error:
The query cannot be run for the following DataObject: CheckDuplicates
InfoPath cannot run the specified query.
The SOAP response indicates that an error occurred:
System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 402). ---> System.FormatException: The string '' is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value)
at System.Xml.Serialization.XmlSerializationReader.ToDateTime(String value)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read19_CheckDuplicates()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer24.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Thanks in advance.
The first problem is that you have the data connection set to query when the form is opened which means it is being queried with empty data. You should turn that option off.
If you are in fact sending the date in the format m/d/yyyy, that is another problem. SOAP requires that dates be sent as XML, which means yyyy-mm-dd. You might be better off making that parameter a string parameter and doing the actual parsing in the web service. That would prevent cryptic errors like this.
Jimmy Rishe / Software Developer / Microsoft MVP
Qdabra Software
In the date picker control I have specified the format as 2001-03-01 and selected "do not display time", but I am still getting the AllXsd error. Do I need to include the time or do I tell it somewhere else what format to use to actually pass the date parameter?
Or is it better , as you say, just to pass a string rather than a date and handle it in the web service.
I can do it however is the best way but I would like to understand why the date is not working as I thought it should.
Thanks again.
The date picker's format doesn't matter. If you're using a date picker, then the underlying data is most likely in the right format.
Did you do as I suggested and turn off the "Query when form is opened" option for that data connection? I think that's the cause of the problem.
Jimmy Rishe / Software Developer / Microsoft MVP
Qdabra Software
Thanks for your help, it was very useful.
I have decided to go ahead and pass the DateTime parameters as strings rather than dates. I am past the allXsd error by doing this, so I guess the original question is resolved. I am still having trouble with the format but this should just be a webservice issue at this point and is unrelated to my original issue.
It looks like I am actually passing 2010-08-26T00:00:00 as a string and I just need to convert that into a date that C# understands.
Thanks again for the help.
It seems I am still having a problem even though I am now passing a string as a parameter rather than a dateTime.
What I have learned in the process of trying to figure this out, is that I can pass the date (as a string) to the web service without any problem. I can also return a value so I can see the results of whatever operation I want to perform, so if for example if I return the same string I just passed in ("2010-08-26T00:00:00") I can see the string is correct. I can also return the length of the string and that is correct (19), but if I do any operation that tries to manipulate the string like a convert or extracting a substring I get an error.
For example if I do
string NewString = StartDate.Substring(1,4);
I see the error "System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string." when I have just seen that the length of the string is 19.
If I do this through the WSDL and manually enter the string I don't get any errors, but if I run the InfoPath form that passes the same string, that is where the issue always occurs.
Is the string passed through an InfoPath parameter different somehow?
Did you do as I suggested twice so far and turn off the option to query the data source when the form is opened? If not, it will still be querying the web service with an empty string as a parameter, and that will cause that error if you try to use Substring() on it.
Jimmy Rishe / Software Developer / Microsoft MVP
Qdabra Software
Here's a new blog post from Hilary that has some good info on dates and datetimes:
http://www.infopathdev.com/blogs/hilary/archive/2010/08/27/looks-can-be-deceiving-dates-date-times-and-quot-t-quot.aspx
Patrick Halstead
Project Manager at Qdabra
Yes, sorry I did not reply to that. I did turn off the option to query the data source when the form is opened and that did fix the first problem with giving an error when the form is loaded, but this is still unrelated to the fact that the web service will no allow me to parse or take apart a parameter I pass to it. It apparently does not matter if it is text or DateTime, I can see the value but if I try to use the value in any way (parse it, substring, convert, extract year, etc.) I get one error or another telling me it is not a string or not a date.
Thanks for the suggested link, a week ago that would have been very helpful to me but that part I have worked my way through. I know I am sending the correct date format and I can display the correct date after it is passed to the web service but I cannot do anything with the variable because it is not recognized as a date, for example it does not recognize 2010-08-30T00:00:00 as a date and I can't perform any function on it. Same result if I pass this as a string.
Again to clarify what confuses me, is if I run my web service everything works perfectly (string or date), but if I pass the parameter through InfoPath I have the problem. FYI this date is also going into a database through a different web method of this same web service and it is a good date, but it is when it is passed as a parameter it fails.
The error you posted a few posts up:
"System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string."
Suggests that the string (
StartDate
) is an empty string. How did you verify that the string is actually of length 19? Could you post some more of your web service's code, starting at the beginning?
Jimmy Rishe / Software Developer / Microsoft MVP
Qdabra Software
I agree that the error indicates that the parameter is empty but here is what I have done to verify the problem I am seeing.
Below my is the complete code for my web method, I have stripped it down to the very bare minimum to exclude something else that could be causing the problem.
I am passing in the string "2010-08-30T00:00:00" and then immediatly returning the value through the web service to my Infopath form and displaying it on the form. It is correctly showing 2010-08-30T00:00:00.
I uncomment the line with
StartDate.Length
and run it again and I display 19. That is correct.
I uncomment the line with
StartDate.Substring(0, 4)
and I get the error mentioned previously indicating the string is empty.
I uncomment the line with
StartDate.GetType()
the type is displayed as System.String.
Here is the complete Web Method:
public
string
CheckDuplicates(
string
StartDate)
//return StartDate.Length.ToString();
//return StartDate.Substring(0, 4).ToString();
//return StartDate.GetType().ToString();
return
StartDate;
I have found out I can look at the string in some other ways besides Length so I am looking at using the C# split method and it looks like I am not getting the errors I get with substring. Thanks for any help you can give, I would really like to understand what is happening here.
I would suggest attaching your Visual Studio debugger to the IIS process (most likely w3svc.exe), setting a breakpoint on the opening brace of this method, and observing the values that way, because I'm stumped as to why this is happening. If StartDate really is that 19 character-long string, then Substring() should work just fine.
I'd also suggest you try this:
public string CheckDuplicates(string StartDate)
{
if(StartDate.Length < 4)
{
return "Please use a valid date.";
}
else
{
return StartDate.Substring(0, 4);
}
}
It's an important practice to validate your inputs.
Jimmy Rishe / Software Developer / Microsoft MVP
Qdabra Software