2013-05-08 58 views
1

當我向iphone發送webservice soap請求時出現錯誤。我該如何解決它?xml soap響應中出現錯誤

這裏是我收到的消息。

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<soap:Body> 
    <soap:Fault> 
    <faultcode>soap:Client</faultcode> 
    <faultstring>Server did not recognize the value of HTTP Header SOAPAction: HelloWorld.</faultstring> 
     <detail /> 
    </soap:Fault> 
</soap:Body> 
</soap:Envelope> 

這裏是我的Objective-C代碼

-(IBAction)buttonClick:(id)sender 
{ 
recordResults = FALSE; 

NSString *soapMsg = 
[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" 
"<HelloWorld xmlns=\"http://tempuri.org/\" />\n" 
"</soap:Body>\n" 
"</soap:Envelope>\n"]; 

//---print it to the Debugger Console for verification--- 
NSLog(soapMsg); 

NSURL *url = [NSURL URLWithString: @"http://servicing2.rotanet.com.tr/service1.asmx"]; 
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 

//---set the various headers--- 
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]]; 
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[req addValue:@"HelloWorld" forHTTPHeaderField:@"SOAPAction"]; 
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 

//---set the HTTP method and body--- 
[req setHTTPMethod:@"POST"]; 
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; 


theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
if (theConnection) { 
    webData = [[NSMutableData data] retain]; 
} 
} 

我一直在這2天。我瘋了。你們有什麼建議嗎?

回答

1

替換此,

[req addValue: @"http://tempuri.org/HelloWorld [req addValue:@"HelloWorld" forHTTPHeaderField:@"SOAPAction"];" forHTTPHeaderField:@"SOAPAction"]; 

,而不是

[req addValue:@"HelloWorld" forHTTPHeaderField:@"SOAPAction"]; 
0

服務器無法找到與您要發送的請求對應的服務。您創建的SOAP事務發送:

"<HelloWorld xmlns=\"http://tempuri.org/\" />\n" 

客戶端期望服務器瞭解哪些內容。在這種情況下,您的服務器不理解的交易請求,並返回:

Server did not recognize the value of HTTP Header SOAPAction: HelloWorld. 

看來,您的SOAP客戶端就好了,只不過操作HelloWorld不對應於服務器上的任何東西。

檢查服務器並確保這是一個有效的操作,並更正客戶端發送有效操作請求或服務器以響應您發送的請求。

0

我想你已經通過了錯誤的SOAPAction

試試這個

[req addValue:@"http://tempuri.org/HelloWorld" forHTTPHeaderField:@"SOAPAction"]