-6

我是电话编程的新手。我已经创建了一个 Web 服务和一个函数,它应该返回从普遍数据库中检索到的记录。但我没有得到输出。它显示了一些这样的异常。任何人都可以告诉我什么是错误。

2013-05-20 18:54:36.502 NewC Newcafezee[1743:11303] <?xml version="1.0" encoding="utf-8"?><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. ---&gt; System.InvalidOperationException: There is an error in XML document (7, 109). ---&gt; System.FormatException: The string '3/1/2013' is not a valid AllXsd value.
   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
   at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
   at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value)
   at System.Xml.Serialization.XmlSerializationReader.ToDateTime(String value)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_OnlineStatus()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.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.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   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>

这段代码有错误吗

 NSString *soapMessage=[NSString stringWithFormat:
                           @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                           "<soap:Envelope \n"
                           "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
                          "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
                          "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                           "<soap:Body>\n"
                           "<OnlineStatus xmlns=\"http://tempuri.org/\"><CafeName>Cyber Cafe Name</CafeName><FromDate>3/1/2013</FromDate><ToDate>5/6/2013</ToDate></OnlineStatus>\n"
                           "</soap:Body>\n"

                           "</soap:Envelope>"];
    NSLog(@"%@",soapMessage);


    NSURL *url = [NSURL URLWithString:@"http://www.ebidmanagerdemo.com/gjHouseOnline/xml/XMLDataService.asmx"];
      NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://tempuri.org/OnlineStatus" forHTTPHeaderField:@"Soapaction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if(theConnection) {
        webData = [NSMutableData data];
    }
    else {
        NSLog(@"theConnection is NULL");

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    NSLog(@"%@",msgLength);
4

1 回答 1

2

System.FormatException:字符串 '3/1/2013' 不是有效的 AllXsd 值。

根据XML Schema Specificationdate time值应该是ISO8601格式,

例如:

2013-01-03T22:16:00
于 2013-05-20T13:40:05.803 回答