2014-11-03 2 views
0

Objective-C iOS에서 Maginto SOAP API를 사용하려고합니다. 로그인 API를 호출하고 SessionID를 얻을 수 있지만 동일한 SessionID를 가진 다른 API를 호출하려고하면 다음 오류가 발생합니다.Objective-C에서 Magento SOAP API를 호출 할 때 오류 발생

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>5</faultcode><faultstring>Session expired. Try to relogin.</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope> 

왜이 오류 메시지가 표시되는지 알 수 없습니다. 누구든지 해결책을 알고 있다면 저를 도우십시오.

미리 감사드립니다. 사람이 다음 솔루션이 있으면 알려주세요

-(void)make_call_to_maginto_api_login{ 
NSString *soapMessage = @" \ 
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:Magento\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> \ 
<SOAP-ENV:Body> \ 
<ns1:login> \ 
<apiUser xsi:type=\"xsd:string\">UserName</apiUser> \ 
<apiKey xsi:type=\"xsd:string\">Password</apiKey> \ 
</ns1:login> \ 
</SOAP-ENV:Body> \ 
</SOAP-ENV:Envelope>"; 

NSURL *url = [NSURL URLWithString:@"http://www.hostname.com/index.php/api/v2_soap/"]; 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
NSString *msgLength = [NSString stringWithFormat:@"%lu",(unsigned long)[soapMessage length]]; 

[request addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[request addValue:@"http://www.hostname.com/login" forHTTPHeaderField:@"SOAPAction"]; 

[request addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 
[request setHTTPMethod:@"POST"]; 
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
if(connection) 
{ 
    self.webData = [NSMutableData data]; 
} 
else 
{ 
    NSLog(@"theConnection is null"); 
}} 

, 그것은 나에게 정말 좋은 것 -

여기 내 로그인 코드입니다. 고마워요 :)

+0

어떻게해야합니까? 그리고 세션 ID API를 가져 오는 방법을 알려주세요. – iphonemaclover

+0

이전에는 SOAP 요청에 문제가 있었기 때문에 변경 작업을 수행하면됩니다. – RJ168

+0

감사합니다. 비누를 사용하여 .svc 서비스를 호출 할 수 있습니까? – iphonemaclover

답변

2

솔루션을 많이 찾은 후,이 문제를 직접 해결했습니다. 나는 SOAP 요청에서 변경을 마쳤으며 지금은 잘 동작한다.

감사합니다.

다음은 SOAP 요청을 발생시키는 Magento Envelope 요청과 메소드를 생성하는 메소드입니다.

- (NSString *)createEnvelope:(NSString *)method forNamespace:(NSString *)ns forParameters:(NSString *)params{ 
NSMutableString *s = [NSMutableString string]; 
[s appendString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"]; 
[s appendFormat:@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"%@\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ns2=\"http://xml.apache.org/xml-soap\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">", ns]; 
[s appendString:@"<SOAP-ENV:Body>\n"]; 
[s appendFormat:@"<%@>%@</%@>", method, [params stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"], method]; 
[s appendString:@"</SOAP-ENV:Body>"]; 
[s appendString:@"</SOAP-ENV:Envelope>"]; 
return s;} 

-(void)login_request{ 
    NSString *parameters = [NSString stringWithFormat:@"<username xsi:type=\"xsd:string\">%@</username><apiKey xsi:type=\"xsd:string\">%@</apiKey>",login_name,login_pwd]; 
    NSString *envelope = [self createEnvelope:@"login" forNamespace:@"urn:Magento" forParameters:parameters]; 

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.YOUR_HOST_NAME.com/index.php/api/v2_soap/"]]; 

    //?wsdl=1 

    [request setHTTPMethod:@"POST"]; 

    NSMutableDictionary *defaultHeaders = [[NSMutableDictionary alloc] init]; 
    [defaultHeaders setValue:@"gzip" forKey:@"Accept-Encoding"]; 
    [defaultHeaders setValue:@"en, en-us;q=0.8" forKey:@"Accept-Language"]; 
    [defaultHeaders setValue:@"text/xml; charset=utf-8" forKey:@"Content-Type"]; 
    [defaultHeaders setValue:@"urn:Mage_Api_Model_Server_HandlerAction" forKey:@"SOAPAction"]; 
    [defaultHeaders setValue:@"com.lognllc.Magento-iOS-Example/1.0.0 (unknown, iPhone OS 8.1, iPhone Simulator, Scale/2.000000)" forKey:@"User-Agent"]; 

    [request setAllHTTPHeaderFields:defaultHeaders]; 
    [request setHTTPBody:[envelope dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    if(connection) 
    { 
     self.webData = [NSMutableData data]; 
    } 
    else 
    { 
     NSLog(@"theConnection is null"); 
    } 
} 
+0

SOAP 요청에이 변경 사항을 넣을 수 있습니까? 고맙습니다. – Rincha

+0

1 시간 이내에 갈 것입니다. – RJ168

+1

친애하는 Rincha, 제 답변을 참조하십시오. 나를 위해 잘 작동, 귀하의 의견을 알려 주시기 바랍니다. – RJ168

관련 문제