views:

260

answers:

1

I'm sending SOAP requests to an external web service. There are several fields that make up the request and one of them is defined as a s:time type.

I would like to set this time field to a value but c# only accepts a datetime type and not just time.

...
soapClient soapService = new soapClient();
sendTime soapRequest = new sendTime();

soapRequest.TimeOfArrival = Convert.ToDateTime("09:00:00");
...

So I have to do the convert because the TimeOfArrival field is set to s:time and for some reason c# requires a s:time to be in the format datetime.

If I just do the following:

soapRequest.TimeOfArrival = "09:00:00";

I get the error 'Cannot implicitly convert type 'string' to 'System.DateTime'

So how can I set the field to just a time?

A: 

If you used VS2k8 to construct the SOAP interface from a WSDL link then soapRequest.TimeOfArrival will be the correct C# type to match the SOAP type.

If C# doesn't have an exactly matching type then it'll use the most appropriate type and I believe, make any appropriate adjustments internally. On that basis, your first piece of code is the correct approach.

Lazarus