Параметр пуст в веб-сервис asmx из цели c - PullRequest
1 голос
/ 29 июня 2011

Я вызываю веб-службу .Net asmx из моего отладчика xcode. В отладчике я вижу, что я передаю какое-то значение, но в веб-службе .net оно отображается пустым

В конце веб-службы я пишу в файл журнала. Я вижу, что метод вызывается, но параметр становится пустым / пустым. Я вставил код ниже. Я также вставил WSDL. Любая причина, почему параметры указаны как пустые

-(void) fetchData: (NSString*)userid 
{
    NSString *requestSoapMsg = 
    [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"
     "<UpdateRegForUser xmlns=\"http://soft.com\">\n"
     "<userid>%@</userid>\n"    
     "</UpdateRegForUser>\n"
     "</soap:Body>\n"
     "</soap:Envelope>\n", userid];

    NSLog(@"%@", requestSoapMsg); // i can see the value here

    NSURL *url = [NSURL URLWithString:@"http://soft.com:8000/services/registration.asmx"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    NSString *requestSoapMsgLength = [NSString stringWithFormat:@"%d", [requestSoapMsg length]];
    [request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"http://soft.com/UpdateRegForUser" forHTTPHeaderField:@"SOAPAction"];
    [request addValue:requestSoapMsgLength forHTTPHeaderField:@"Content-Length"];

    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[requestSoapMsg dataUsingEncoding:NSUTF8StringEncoding]];

    NSError *error;
    NSURLResponse *response;

    NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    if(!result)
        NSLog(@"FAILEDDDDDDDDD!!");

WSDL -

POST /services/registration.asmx HTTP/1.1

Host: soft.com


Content-Type: text/xml; charset=utf-8

Content-Length: length

SOAPAction: "http://soft.com/UpdateRegForUser"

<?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>
    <UpdateRegForUser xmlns="http://soft.com/">
      <userid>string</userid>
    </UpdateRegForUser>
  </soap:Body>
</soap:Envelope>

1 Ответ

0 голосов
/ 30 июня 2011

Я понял проблему.

Я написал консольное приложение на C # и вызвал веб-сервис.В то же время я захватил след от скрипача.Трассировка фиддлера показала мне, что xmlns: soap = "http://schemas.xmlsoap.org/soap/envelope/" должен предшествовать xsi. Я сохранил xml и сделал свой запрос xml ТОЧНО таким же. Он начал работать.

...