DevT
DevT

Reputation: 4933

Pass date to web service as object property

i'm new to web services and i try to find solution but cudn't find any solution.

i'm trying send object as a parameter to web service.

    [WebMethod]
    public bool CreatePatientService(Patient p)
    {
        AdminService AsRef = new AdminService();
        return AsRef.CreatePatient(p);
    }

my patient class is as follows:

[Serializable]
public class Patient
{

    public string NIC { get; set; }
    public string FullName { get; set; }
    public string FirstName { get; set; }
    public string Surname { get; set; }
    public string Title { get; set; }
    public string Gender { get; set; }
    public string CivilStatus { get; set; }
    public DateTime DOB { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string Address3 { get; set; }
}

then i used SOAPUi to called Web service.

i called the request as below :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:CreatePatientService>
         <!--Optional:-->
         <tem:p>
            <!--Optional:-->
            <tem:NIC>15487236</tem:NIC>
            <!--Optional:-->
            <tem:FullName>awdss</tem:FullName>
            <!--Optional:-->
            <tem:FirstName>qewretr</tem:FirstName>
            <!--Optional:-->
            <tem:Surname>qscv</tem:Surname>
            <!--Optional:-->
            <tem:Title>Mr</tem:Title>
            <!--Optional:-->
            <tem:Gender>M</tem:Gender>
            <tem:CivilStatus>S</tem:CivilStatus>
            <tem:DOB>01/02/2002</tem:DOB>
            <!--Optional:-->
            <tem:Address1>nikhno</tem:Address1>
            <!--Optional:-->
            <tem:Address2>asdf</tem:Address2>
            <!--Optional:-->
            <tem:Address3>125</tem:Address3>
         </tem:p>
      </tem:CreatePatientService>
   </soapenv:Body>
</soapenv:Envelope>

then its give following error. how can i solve it ?

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (19, 49). ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseUInt32(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.UInt16.Parse(String s, NumberStyles style, NumberFormatInfo info)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_TblPatient(Boolean isNullable, Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read7_CreatePatientService()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer8.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.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()</faultstring>
         <detail/>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

If i removed DOB (Date) then its working properly.

i refer following post. but cudn't work it.

Proper DateTime Format for a Web Service

please help.. Thanks...

Upvotes: 3

Views: 4365

Answers (1)

Mike Parkhill
Mike Parkhill

Reputation: 5551

A DateTime needs to have time values as well as the date, so the fact that you're missing the hour, minutes, seconds, etc. is what's breaking it.

yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz is the expected format.

e.g. 2002-02-01T00:00:00.0

XML deserialize DateTime Format

Upvotes: 5

Related Questions