肥皂解析问题

时间:2013-06-21 19:03:13

标签: iphone ios objective-c soap

我需要解析Soap Request,但我遇到了以下问题,有人可以帮我解决这个问题,因为我是肥皂新手。我知道你是否需要有关代码的任何其他信息

这是Soap Request

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>

2 个答案:

答案 0 :(得分: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"老实说,我不知道它应该是什么,在这方面你可能比我更了解。只是想我可能会提到它,因为它似乎是你的标题,服务器不理解。

答案 1 :(得分:0)

尝试将HTTP字段SOAPAction添加到请求中:

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

另请考虑检查this project