2010-07-20 48 views
3

我嘗試Web服務連接到我的代碼,我得到了錯誤的服務器無法識別iPhone中HTTP Header SOAPAction的值?

「服務器無法識別的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]]; 

請指引我錯過了什麼IAM?

+0

你試過沒有提供SOAPAction頭呢? – slf 2010-07-20 13:36:51

+0

我知道它的偏離主題的建議,但爲什麼你使用網絡連接它使事情更方便 – amar 2013-04-15 05:56:48

回答

1
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

如果這是你自己的網絡服務,檢查是否在您的 「servername.com/Hello」查詢等於Web服務中的命名空間。

在ASP.Net它定義一樣:

[WebService(Namespace="servername.com/Hello")] 
相關問題