简体   繁体   English

如何以编程方式从iPhone应用程序将参数发送到Web方法(Web服务)?

[英]How to send parameter to a webmethod (web service) from iphone application programmatically?

I have develop a web service which provides the hospital names of a particular state inside a iphone application. 我已经开发了一个Web服务,该服务在iphone应用程序中提供特定州的医院名称。 In my application there are different states in table view. 在我的应用程序中,表视图中有不同的状态。 When a user select a particular state, I need to send the that particular state name to the web service so that it can display the hospitals belongs to that particular state. 当用户选择特定州时,我需要将该特定州名称发送到Web服务,以便它可以显示属于该特定州的医院。 How can I achieve this???Please Help me. 我该如何实现?请帮助我。 I stuck here for long time.....thanks in advance.... 我在这里待了很长时间.....提前致谢....

That all depends on your webservice. 这一切都取决于您的Web服务。 If you are using a RESTful webservice you could do something like http://mysite.com?state=NewYork and the webservice can pull the state parameter and find that the user is looking for New York. 如果您使用的是RESTful Web服务,则可以执行类似http://mysite.com?state=NewYork的操作,并且该Web服务可以提取state参数并发现用户正在寻找纽约。

If you are using a SOAP webservice you would have to follow the schema defined in the webservice's WSDL. 如果使用的是SOAP Web服务,则必须遵循Web服务的WSDL中定义的架构。

Edit 1: 编辑1:

In either case: In the iOS app you can determine which table row was selected by making your class implememnt UITableViewDelegate and implementing tableView:didSelectRowAtIndexPath: ( Documentation Here ) At this point you can determine which state you are looking for and add that value to the service call. 无论哪种情况:在iOS应用中,您都可以通过使类实现UITableViewDelegate并实现tableView:didSelectRowAtIndexPath:( 此处为文档 )来确定选择了哪个表行,此时,您可以确定要查找的状态并将该值添加到服务电话。

Edit 2: 编辑2:

NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yoursite/webService"]] retain];
NSString *bodyLength =  [NSString stringWithFormat:@"%d", [bodyString length]];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:bodyLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[bodyString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *myConnection = [NSURLConnection connectionWithRequest:request delegate:self];
[myConnection start];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM