5

「iOSでSOAPを使用する方法」については、ウェブ上で利用できるものがたくさんあることは知っていますが、それでもSAOPの要求と応答に従うことができませんでした。ヘルプは大歓迎です。単純なNSURLConnection要求と応答のSOAP要求を使用します

POST ???.asmx HTTP/1.1
Host: ???
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetMessages"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetMessages xmlns="http://tempuri.org/">
      <GroupName>string</GroupName>
      <Date>dateTime</Date>
    </GetMessages>
  </soap:Body>
</soap:Envelope>

SOAP応答

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetMessagesResponse xmlns="http://tempuri.org/">
      <GetMessagesResult>xml</GetMessagesResult>
    </GetMessagesResponse>
  </soap:Body>
</soap:Envelope>

これが私がリクエストを送信するために書いたコードです。

NSString *soapMessage = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                         "<soap:Body>\n"
                         "<GetMessages xmlns=\"http://tempuri.org/\">\n"
                         "<GroupName>%@</GroupName>\n"
                         "<Date>%@</Date>\n"
                         "</GetMessages>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n"
                         , txtfield1.text
                         , textfield2.text
                         ];
NSLog(@"soapMessage: \n%@",soapMessage);

NSURL *url = [NSURL URLWithString:@"???.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/GetMessages" 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] retain];
else
    NSLog(@"theConnection is NULL");

このエラーが発生しますconnectionDidFinishLoading

  <soap:Fault>
     <faultcode>soap:Server</faultcode>
     <faultstring>Server was unable to process request. ---&gt; SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.</faultstring>
     <detail />
  </soap:Fault>

私はこのリンクを参照し、このリンクのコードを使用し、都合に合わせて変更して機能させまし

私の質問は、リクエストを送信して懸念応答を受信する方法です

よろしくお願いします

4

1 に答える 1

2

この問題は、soap メッセージの送信/受信とはまったく関係がないようですが、送信する値とはまったく関係dateTimeがありません。正しい形式ではありません。

=> サーバーはリクエストを処理できませんでした。---> SqlDateTime オーバーフロー。1753 年 1 月 1 日 12:00:00 AM から 9999 年 12 月 31 日 11:59:59 PM の間である必要があります。

NSDateFormatter を使用して、要求された形式で日付文字列を書き込みます

于 2013-01-11T09:52:59.190 に答える