2013-01-11 34 views
5

Tôi biết htere là rất nhiều nội dung có sẵn trên web cho "cách sử dụng SOAP trong iOS", nhưng tôi vẫn thất bại khi thực hiện SAOP Yêu cầu & phản hồi. Trợ giúp được đánh giá rất cao. tôi sử dụng đơn giản NSURLConnection cho yêu cầu & phản ứng SOAP requstiOS - cách thực hiện yêu cầu SOAP và nhận được phản hồi quan tâm

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 đáp ứng

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> 

Đây là mã tôi đã viết để gửi yêu cầu ..

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"); 

Tôi gặp lỗi này trong 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> 

tôi gọi this link & used the code in this link & modified according to my convenience to make it worked

Câu hỏi của tôi là làm thế nào để gửi yêu cầu & nhận được phản hồi quan tâm

Thanks a lot trước

Trả lời

2

vấn đề dường như không liên quan đến việc gửi/recv của tin nhắn xà phòng ở tất cả NHƯNG với giá trị bạn gửi là dateTime - nó không có định dạng đúng.

=> Máy chủ không thể xử lý yêu cầu. --- > tràn SqlDateTime. Phải từ 1/1/1753 12:00:00 AM và 12/31/9999 11:59:59 PM.

sử dụng một NSDateFormatter để viết chuỗi ngày theo định dạng yêu cầu

+0

Hey. Cảm ơn rất nhiều .. Nó hoạt động hoàn hảo sau khi định dạng ngày & giờ –

Các vấn đề liên quan