3

我是网络服务的新手,我试图找到解决方案,但找不到任何解决方案。

我正在尝试将对象作为参数发送到 Web 服务。

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

我的病人班如下:

[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; }
}

然后我使用 SOAPUi 来调用 Web 服务。

我将请求称为如下:

<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>

然后它给出以下错误。我该如何解决?

<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>

如果我删除了 DOB(日期),那么它可以正常工作。

我参考以下帖子。但不能正常工作。

Web 服务的正确日期时间格式

请帮忙..谢谢...

4

1 回答 1

5

DateTime 需要有时间值和日期,所以你错过了小时、分钟、秒等的事实是破坏它的原因。

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

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

XML 反序列化 DateTime 格式

于 2012-12-19T20:12:30.863 回答