iOS-如何发出SOAP请求和收到关注回复 [英] iOS - how to make SOAP request & receive the concern response

查看:83
本文介绍了iOS-如何发出SOAP请求和收到关注回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道网上有很多关于如何在iOS中使用SOAP"的资料,但是我仍然无法遵循SAOP Request&回复.非常感谢帮助. 我将简单的NSURLConnection用于请求&回复 SOAP Requst

I know htere is lot of stuff available on web for "how to use SOAP in iOS", but still I failed in doing for following SAOP Request & response. Help is greatly Appreciated. I use the simple NSURLConnection for request & response SOAP Requst

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>

这是我编写的用于发送请求的代码.

Here is the code I wrote for sending the request..

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>

我引用了此链接 & 在此使用了代码链接和根据我的方便进行了修改以使其起作用

I referred to this link & used the code in this link & modified according to my convenience to make it worked

我的问题是如何发送请求&收到关注回复

非常感谢

推荐答案

该问题似乎与在所有情况下以肥皂形式发送/接收肥皂消息无关,但与您以dateTime发送的值无关-它没有正确的格式.

the problem seems not related to the send/recv of soap messages at all BUT to the value you send as dateTime -- it doesn't have the correct format.

=>服务器无法处理请求. ---> SqlDateTime溢出.必须在1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间.

=> Server was unable to process request. ---> SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

使用NSDateFormatter以请求的格式写入日期字符串

这篇关于iOS-如何发出SOAP请求和收到关注回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆