iPhone 使用 Restful WCF 服务 [英] IPhone consuming restful WCF service
问题描述
我目前有一个简单的 WCF 服务,它运行一个返回 XML 的 get 请求,http://a446062738bb4f0aa2d8fd975aac602f.cloudapp.net/Service1.svc/GetALLPictures/10...我正在尝试使用 [NSString stringWithURL:] 用 XML 内容填充字符串,但是这不起作用,我尝试使用Unicode 和 UTF8 编码来获取字符串,什么也没有,我已经在服务器上设置了 crossclient.xml,我在 Silverlight 应用程序中以类似的方式使用了该服务.(我也使用 NSURLCOnnection 和 NSURLRequest 尝试了上述所有方法)
谢谢
I currently have a simple WCF service running with one get request which returns XML, http://a446062738bb4f0aa2d8fd975aac602f.cloudapp.net/Service1.svc/GetALLPictures/10... Im trying to use [NSString stringWithURL:] to populate the string with the XML content, however this is not working, ive tried using Unicode and UTF8 encoding to get the string and nothing, I have set the crossclient.xml on the server and i have consumed the service in a similar way in a silverlight application. (I have also tried all of the above using NSURLCOnnection and a NSURLRequest)
Thanks
推荐答案
你的意思是 +stringWithContentsOfURL:
?我没有看到任何问题:
You mean +stringWithContentsOfURL:
? I'm not seeing any trouble with this:
NSString *xml = [NSString stringWithContentsOfURL:
[NSURL URLWithString:
@"http://a446062738bb4f0aa2d8fd975aac602f.cloudapp.net/Service1.svc/GetALLPictures/10"]];
它返回这个:
<GetAllPicturesResponse xmlns="http://tempuri.org/">
<GetAllPicturesResult
xmlns:a="http://schemas.datacontract.org/2004/07/TestCloudService_WebRole"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Coordinate><a:latitude>0</a:latitude><a:longitude>0</a:longitude>
</a:Coordinate><a:Coordinate><a:latitude>-50</a:latitude>
<a:longitude>-80</a:longitude></a:Coordinate></GetAllPicturesResult>
</GetAllPicturesResponse>
除非您在后台线程上执行此操作,否则您会想要使用 NSURLConnection
,但它看起来不错.
You'll want to use NSURLConnection
unless you're doing this on a background thread, but it seems fine.
这篇关于iPhone 使用 Restful WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!