2013-06-21 93 views
0

我需要解析一個肥皂請求,但我有以下問題,有人可以幫助我解決這個問題,因爲我是肥皂新手。我知道如果您需要關於代碼的任何其他信息肥皂分析問題

這裏是SOAP請求

POST /LocatorAPI/LocatorService.asmx HTTP/1.1 
Host: staging2.abc.spatialpoint.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://spatialpoint.com/abc/locator/FindNearby" 

<?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> 
<FindNearby xmlns="http://spatialpoint.com/abc/locator/"> 
    <request>   <Token>string</Token> 
    </request> 
</FindNearby> 
</soap:Body> 
</soap:Envelope> 

這裏是我的目標C代碼。

NSString* soapMessage = 
[NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%@%@", 
@"<?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>", 
@"<FindByProperty xmlns=\"http://spatialpoint.com/abc/locator/ \">", 
@"<request>", 
@"<Token>", 
theRadius, 
@"</Token>", 
@"</request>", 
@"</FindByProperty>", 
@"</soap:Body>", 
@"</soap:Envelope>"]; 




NSURL *url = [NSURL URLWithString:@"http://staging2.abc.spatialpoint.com/LocatorAPI/LocatorService.asmx"]; 
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 

// HTTP headers 
NSString *messageLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[req addValue:messageLength forHTTPHeaderField:@"Content-Length"]; 
// method = POST 
[req setHTTPMethod:@"POST"]; 

// BODY 
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

// send request 
self.connection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
if (self.connection != nil) 
{ 
    self.receivedData = [NSMutableData data]; 
} 
else 
{ 
    [[UIApplication sharedApplication]  
    setNetworkActivityIndicatorVisible:NO]; 
} 

我得到這個錯誤。

2013-06-19 02:22:49.942 SoapClient[42229:c07] Response: 
2013-06-19 02:22:49.943 SoapClient[42229:c07] <?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: .</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> 

回答

0

嘗試添加HTTP場的SOAPAction請求:

[req setValue:@"http://spatialpoint.com/abc/locator/FindNearby" forHTTPHeaderField:@"SOAPAction"]; 

還要考慮檢查this project

0

我想把它放在評論中,但它太大了。這裏是我的肥皂請求代碼:

soapMsg = 
    [NSString stringWithFormat: 
    @"<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
    "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" 
    "<soap12:Body>" 
    "<WebServiceMethod xmlns=\"http://tempuri.org/\">" 
    "<MessageToServer><![CDATA[%@]]></MessageToServer>" 
    "</WebServiceMethod>" 
    "</soap12:Body>" 
    "</soap12:Envelope>" 
    ,encryptedString]; 

其中encryptedString是我的服務器接收和解密的消息。 WebServiceMethod是我的webservices中的方法名稱,MessageToServer是webservice要求的對象的名稱。我也使用ASIFormDataRequest而不是NSMutableURLRequest。這可能會有所作爲。 ASIHTTP庫對我來說非常好。

另一點。我的內容類型是@"application/soap+xml; charset=utf-8"老實說,我不知道它應該是什麼,在這方面你可能比我更瞭解我。只是想我可能會提到它,因爲它似乎是你的標題,服務器不理解。

+0

我不能使用ASIHTTP不再受支持。 – Anil

+0

你爲什麼設置消息長度兩次?並檢查我的編輯另一點可能會幫助你,可能不會。 – Putz1103

+0

消息長度兩次是錯字,只是更新了代碼。 – Anil