2012-12-19 64 views
2

我是新来的Web服务,我试图找到解决方案,但没有找到任何解决方案。将对象的属性传递给Web服务

我想发送对象作为参数到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(日期),那么它的工作正常。

我指下面的帖子。但不能工作。

Proper DateTime Format for a Web Service

请帮助..谢谢...

回答

4

一个DateTime需要有时间值以及日期,所以实际上你失踪时,分,秒等是什么打破了它。

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

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

XML deserialize DateTime Format

+0

感谢名单......这个工作正常....ü保存我的天.... :) – DevT

相关问题