2013-06-17 6 views
0

У меня есть мыло WebService в PHP, и я стараюсь, чтобы потреблять его из Objective-C, но я не получаю никакого ответаПотребляя Web Service не работает

Запрос в порядке? вебсервис появляется работа нормально ..

вот мой код в PHP

<?php 
    require_once('lib/nusoap.php'); //include required class for build nnusoap web service server 

     // Create server object 
     $server = new soap_server(); 

     // configure WSDL 
     $server->configureWSDL('Upload File', 'urn:uploadwsdl'); 

     // Register the method to expose 
     $server->register('cadastraUsuario'); 

     // Define the method as a PHP function 

    function cadastraUsuario($_name, $_surname, $_location, $_email, $_password, $_gender, $_foto, $_tipo, $_dateLogin) { 
      echo "tetdta"; 
     if($_name and $_surname) 
     { 
      $name  = strip_tags(trim(htmlentities($_name))); 
      $surname = strip_tags(trim(htmlentities($_surname))); 
      $location = strip_tags(trim(htmlentities($_location))); 
      $email  = strip_tags(trim(htmlentities($_email))); 
      $password = strip_tags(trim(htmlentities($_password))); 
      $gender  = strip_tags(trim(htmlentities($_gender))); 
      $tipo  = strip_tags(trim(htmlentities($_tipo))); 
      $_foto  = $_foto; 

      //Consulta o email para ver se ja esta cadastrado 
      $sql_consulta = "select * from `cdusers` where email = '".$email."'"; 
      $result_consulta = mysql_query($sql_consulta); 
      $row = mysql_num_rows($result_consulta); 

      header('Content-type: text/xml'); 
      if($row > 0) 
      { 
       print' 
       <resultado> 
        <mensagem_cadastro>Este e-mail ja esta cadastrado!</mensagem_cadastro> 
       </resultado> 
       '; 
      } 
      else 
      { 
       $sql = "INSERT INTO `CDUsers` (`name`, `surname`, `location`, `email`, `password`, `gender`, `foto`, `tipo`, `dateLogin`) 
         VALUES ('$name', '$surname', '$location', '$email', '$password', '$gender', '$foto', '$tipo', '')"; 

       $result = mysql_query($sql); 

       //Se a execucao no banco estiver ok ou nao 
       if($result) 
       { 
        print ' 
        <resultado> 
         <mensagem_cadastro>Usuário Cadastrado com sucesso!</mensagem_cadastro> 
        </resultado> 
        '; 

       } 
       else 
        print ' 
        <resultado> 
         <mensagem_cadastro>Erro ao cadastrar o ususario!</mensagem_cadastro> 
        </resultado> 
        '; 
      } 
     } 
     else 
     { 
      echo "nao entrou na condição"; 
     } 
    } 



$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; 
$server->service($HTTP_RAW_POST_DATA); 

?> 

и вот мой код в Objective-C

NSString *soapMessage = [NSString stringWithFormat:@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"; 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>\n" 
          "<cadastraUsuarioRequest>" 
          "<name>%@</name>" 
          "<surname>%@</surname>" 
          "<location>%@</location>" 
          "<email>%@</email>" 
          "<password>%@</password>" 
          "<gender>%@</gender>" 
          "<foto>%@</foto>" 
          "<tipo>m</tipo>" 
          "<dateLogin></dateLogin>" 
          "</cadastraUsuarioRequest>" 
          "</SOAP-ENV:Body>" 
          "</SOAP-ENV:Envelope>",txtName.text, txtSurName.text, txtLocation.text, txtEmail.text, txtPassword.text,gender,foto]; 

    NSLog(soapMessage); 
    NSString *enderecoWS = @"http://www.url.it/cms/soap/server.php"; 
    NSURL *url = [NSURL URLWithString:enderecoWS]; 

    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://www.url.it/cms/soap/server.php/cadastraUsuario"; forHTTPHeaderField:@"SOAPAction"]; 
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if(theConnection) 
    { 
     if(!webData) 
      webData = [[NSMutableData data] retain]; 
    } 
    else 
    { 
     //NSLog(@"theConnection is NULL"); 
    } 
} 

метод из деталей веб-сервиса:

Закрыть

Имя: cadastraUsua рио Переплет: WebServiceBinding Endpoint:

HTTP: // www.url.it/cms/soap/server.php SOAPAction:

HTTP: // www.url.it/cms/soap/server.php/cadastraUsuario Стиль: RPC

Входной сигнал: использование: кодируются пространство имен: encodingStyle:

http://schemas.xmlsoap.org/soap/encoding/ сообщение:

cadastraUsuarioRequest части: Выход: использование: кодируются пространства имен:

encodingStyle: HTTP://schemas.xmlsoap.org/soap/encoding/ сообщения:

cadastraUsuarioResponse части: Пространство имен: Транспорт:

http://schemas.xmlsoap.org/soap/http Документация:

ответ

0

Ваш код выглядит правильно, есть вы реализовали свои методы делегата, например: функция

NSURL *url = [NSURL URLWithString:@"http://google.co.uk"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

(void) [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; 

делегат:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    NSLog(@"got response back"); 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    NSLog(@"http data: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 
} 

Проверьте веб-службы HTTP ответа заголовка, это различные в зависимости от способа его реализовать, но успешный запрос должен возвращать 201. см here для других кодов

NSError *error; 
NSHTTPURLResponse *response; 
(void) [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
NSLog(@"Response error: http response: %@", response.statusCode);  
+0

да, я уже реализован ... но не получите ответа ... в receiveResponse и receiveData .... PLS, см. мое редактирование – user2486146

+0

Какой код состояния у вас получить? Вы протестировали свой запрос с помощью клиентского теста, такого как Mac [SOAP client] (http://ditchnet.org/soapclient/) –

+0

Я имею в виду, что проблема связана с веб-сервисом – user2486146

Смежные вопросы