如何在反应原生中消费肥皂服务?

时间:2017-02-08 13:42:14

标签: reactjs react-native xmlhttprequest

我是新的反应本地人并且想要使用肥皂服务,但没有得到任何api这样做。我用json解析器使用了fetch api for Rest服务。是否有任何api可用于使用soap服务并在react-native中解析xml。在ios中,我们创建了soap信封并发送到服务器,如:

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/XMLSchem\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                         "<soap:Body>\n"
                         "<GetCitiesByCountry xmlns=\"http://www.webserviceX.NET\">\n"
                         "<CountryName>%@</CountryName>\n"
                         "</GetCitiesByCountry>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n",@"India"];

NSURL *url = [NSURL URLWithString:@"http://webservicex.com/globalweather.asmx"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

[theRequest addValue: @"http://www.webserviceX.NET/GetCitiesByCountry"
  forHTTPHeaderField:@"SOAPAction"];

[theRequest addValue: [NSString stringWithFormat:@"%lu",(unsigned long)[soapMessage length]]
  forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

self.responseData = [[NSMutableData alloc]init];

NSURLSession *soapSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];

NSURLSessionDataTask *dataTask = [soapSession dataTaskWithRequest:theRequest];

[dataTask resume];

我正在寻找反应原生的东西。

0 个答案:

没有答案