Сервер не распознал значение HTTP-заголовка SOAPAction в iPhone? - PullRequest
3 голосов
/ 20 июля 2010

Я пытаюсь подключить веб-службы к своему коду. Я получил сообщение об ошибке:

"Сервер не распознал значение HTTP-заголовка SOAPAction"

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"
                         "<Hello xmlns=\"http://viium.com/\">\n"
                         "<name>%@</name>\n"
                         "</Hello>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n", @"new"
                         ];
NSLog(soapMessage);

NSURL *url = [NSURL URLWithString:@"http://viium.com/WebService/HelloWorld.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://viium.com/Hello" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

Пожалуйстаукажи мне, чего мне не хватает?

Ответы [ 2 ]

1 голос
/ 26 мая 2011
NSURL *url = [NSURL URLWithString:@"https://servername.com/WebService/WebServicename.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"servername.com/Hello" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection  *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

вот ссылка,

http://abhicodehelp.blogspot.com/2010/12/handling-soap-with-iphone.html

это может вам помочь ..

0 голосов
/ 11 августа 2011

Если это ваш собственный веб-сервис, проверьте, соответствует ли ваш «servername.com/Hello» в запросе пространству имен в веб-сервисе.

В ASP.Net это определяет как:

[WebService(Namespace="servername.com/Hello")]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...