Reputation: 3408
I have a web service with input parameters. The relevant XSD in the WSDL is below
When I added this WSDL as Service Reference in Visual Studio, it generated a class with the corresponding fields asSystem.DateTime
. Below is an example of the field in Reference class added for WSDL
private System.Nullable<System.DateTime> startDateField;
My binding to the service to create client is CustomBinding below
protected CustomBinding GetCustomBinding()
{
var customBinding = new CustomBinding() { Name = "CustomBinding" };
customBinding.Elements.Add(new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap11 });
var securityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityBindingElement.AllowInsecureTransport = true;
securityBindingElement.EnableUnsecuredResponse = true;
securityBindingElement.IncludeTimestamp = false;
customBinding.Elements.Add(securityBindingElement);
customBinding.Elements.Add(new HttpTransportBindingElement());
return customBinding;
}
My c# code to assign input
myobject.input.endDate = Convert.ToDateTime(endDate);
After assigning input values, I called a web method to see in Fiddler
that all date parameters are missing in Request.
I tried to test in SoapUI. It looks like the service expects date in the format yyyy-MM-dd
though the type is of date. The webservice returns data only when I supply date in the format yyyy-MM-dd
.
I'm not sure if it is something to do with the expected date format by web service. Obviously, I can't send in format yyyy-MM-dd as .Net generated reference class has DateTime
but not string
data type.
I tried to forcibly set Specified
to true
myobject.input.endDate = Convert.ToDateTime(endDate).Date;
myobject.input.endDateSpecified = true;
I got the below error:
A value was being set that exceeded the maximum allowable field length.
Now, I suspect that the web service expects Date but .Net is trying to send DateTime which might be extending its length
Upvotes: 1
Views: 2209
Reputation: 3408
It looks like my last code worked but the error was due to another field.
myobject.input.endDate = Convert.ToDateTime(endDate).Date;
myobject.input.endDateSpecified = true;
Upvotes: 3