2015-06-15 6 views
0

Я пытаюсь разработать приложение, которое использует данные из службы SOAP. это первый раз, когда я использую SOAP-сервис. Прочитав несколько руководств, я подумал, что смогу правильно установить запрос на службу, но всегда получаю ошибки в ответе. Что не так ?!SOAP в приложении iOS

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
       "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns1=\"urn:Lottery.Intf-ILottery\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:enc=\"http://www.w3.org/2003/05/soap-encoding\">\n" 
       "<env:Body>\n" 
       "<ns1:GetUpcomingLotteries env:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\">\n" 
       "<EntityID xsi:type=\"xsd:int\">2</EntityID>\n" 
       "<Password xsi:type=\"xsd:string\">[email protected]</Password>\n" 
       "<SortBy xsi:type=\"xsd:int\">0</SortBy>\n" 
       "<limit xsi:type=\"xsd:int\">0</limit>\n" 
       "</ns1:GetUpcomingLotteries>\n" 
       "</env:Body>\n" 
       "</env:Envelope>"]; 


NSURL *sRequestURL = [NSURL URLWithString:@"xxxxxxxxx"]; 
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL]; 
NSString *sMessageLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 

[myRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[myRequest addValue: @"urn:Lottery.Intf-ILottery/GetUpcomingLotteries" forHTTPHeaderField:@"SOAPAction"]; 
[myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"]; 

[myRequest setHTTPMethod:@"POST"]; 
[myRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

NSError *error; 
NSURLResponse *response; 
NSData *urlData=[NSURLConnection sendSynchronousRequest:myRequest returningResponse:&response error:&error]; 
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; 
+0

какая ошибка? – iphonemaclover

+0

@iphonemaclover no get data ... –

+0

означает, что ваш конверт с мылом недействителен. Попробуйте SOA-клиент, чтобы протестировать ваш API и получить там свой конверт, а затем протестировать – iphonemaclover

ответ

1

ATTACHED PROJECT HERE СКАЧАТЬ // в файле .h

#import "TBXML.h" 

@property(retain,nonatomic)NSString *xmlString; 

@property(nonatomic,retain)NSMutableData *webResponseData; 

// в файле .m

-(void)method_GetUpcomingLotteries 
{ 



    NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
          "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns1=\"urn:Lottery.Intf-ILottery\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:enc=\"http://www.w3.org/2003/05/soap-encoding\">\n" 
          "<env:Body>\n" 
          "<ns1:GetUpcomingLotteries env:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\">\n" 
          "<EntityID xsi:type=\"xsd:int\">2</EntityID>\n" 
          "<Password xsi:type=\"xsd:string\">[email protected]</Password>\n" 
          "<SortBy xsi:type=\"xsd:int\">0</SortBy>\n" 
          "<limit xsi:type=\"xsd:int\">0</limit>\n" 
          "</ns1:GetUpcomingLotteries>\n" 
          "</env:Body>\n" 
          "</env:Envelope>"]; 


    NSURL *sRequestURL = [NSURL URLWithString:@"xxxxxxxxx"]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:sRequestURL]; 
    NSString *sMessageLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 

    [request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [request addValue: @"urn:Lottery.Intf-ILottery/GetUpcomingLotteries" forHTTPHeaderField:@"SOAPAction"]; 
    [request addValue: sMessageLength forHTTPHeaderField:@"Content-Length"]; 

    [request setHTTPMethod:@"POST"]; 



    [request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSLog(@"soapMessage===\n %@",soapMessage); 

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

    if(theConnection) { 
     NSLog(@"hiii"); 
     [self showUpdating]; 
     self.webResponseData = [NSMutableData data]; 
    }else { 
     NSLog(@"Some error occurred in Connection"); 

     [self showNetworkError]; 
    } 

} 


- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"Received Bytes from server: %lu", (unsigned long)[self.webResponseData length]); 

    NSString * strXml = [[NSString alloc] initWithBytes: [self.webResponseData mutableBytes] length:[self.webResponseData length] encoding:NSUTF8StringEncoding]; 

    NSLog(@"---- %@" ,strXml); 

    TBXML *sourceXML = [[TBXML alloc] initWithXMLString:strXml error:nil]; 
    TBXMLElement *rootElement = sourceXML.rootXMLElement; 
    TBXMLElement *entryElement = [TBXML childElementNamed:@"soap:Body" parentElement:rootElement]; 




} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 

       [self.webResponseData setLength:0]; 
      } 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
       [self.webResponseData appendData:data]; 
    } 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
       NSLog(@"Some error in your Connection. Please try again."); 

       [self showNetworkError]; 

      } 

Или Открыть FireFox Установка расширения SOA клиента Test Там API

enter image description here

enter image description here

Обновления При регистрации в клиенте SOA я получаю следующий заголовок

<?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><GetUpcomingLotteries xmlns="http://tempuri.org/"><EntityID>2</EntityID><Password>[email protected]</Password><SortBy>0</SortBy><limit>0</limit></GetUpcomingLotteries></soap:Body></soap:Envelope> 

И следующий ответ (ЗНАЧИТ ЕГО сервере ошибка может быть)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
<title>500 - Internal server error.</title> 
<style type="text/css"> 
<!-- 
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} 
fieldset{padding:0 15px 10px 15px;} 
h1{font-size:2.4em;margin:0;color:#FFF;} 
h2{font-size:1.7em;margin:0;color:#CC0000;} 
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; 
background-color:#555555;} 
#content{margin:0 0 0 2%;position:relative;} 
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} 
--> 
</style> 
</head> 
<body> 
<div id="header"><h1>Server Error</h1></div> 
<div id="content"> 
<div class="content-container"><fieldset> 
    <h2>500 - Internal server error.</h2> 
    <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3> 
</fieldset></div> 
</div> 
</body> 
</html> 

enter image description here

+0

NSURL * sRequestURL = [NSURL URLWithString: @ "XXXXXXXXX"] Добавить свой базовый url здесь! – iphonemaclover

+0

okay im проверить сейчас и скоро вернуться –

+0

мой url: http://isapi.mekashron.com/SmartWinners/LotteryWS.dll/wsdl/ILottery и SoapAction: GetUpcomingLotteries –