肥皂web服务不工作在iphone
我正在尝试下面的代码,肥皂web service.It不工作。
请帮助我。
链接
服务
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" "<request xmlns=\"http://searchupc.com/GenerateBarcode\">\n" "<auth>5ggpf54TRghbnIvqS2XVGQQ0q6qCNuJ</auth>\n" "<method>FetchProductByUPC</method>" "<params>" "<upc>026274920257</upc>" "</params>" "</request>\n" "</soap:Body>\n" "</soap:Envelope>\n" ]; NSLog(soapMessage); NSURL *url = [NSURL URLWithString:@"http://www.simpleupc.com/api/"]; 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://searchupc.com/GenerateBarcode/" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; NSLog(@"SOAP CONNECTED qqq%@",theRequest); NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
我发现wsdlToObjc相当不错。 它从WSDL为您生成客户端ObjC绑定。 您可以通过http://code.google.com/p/wsdl2objc/下载它。 链接http://www.priyaontech.com/2012/10/soap-based-webservices-integration-in-an-ios-app/用示例项目解释了它的用法。
检查http://sudzc.com/ 。 它会为你生成xcode项目。
1:inputWSDL的Web地址进行转换(如果受保护,则input用户名和密码)
2:select要创build的代码包的types(目标c)并下载。
只需将“生成的”文件夹拖放到项目中,即可访问所有的SOAP消息。
尝试这个。 它真的很容易和简单。