IPhone consuming restful WCF service

2019-08-31 13:34发布

问题:

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

回答1:

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"]];

It's returning this:

<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>

You'll want to use NSURLConnection unless you're doing this on a background thread, but it seems fine.



标签: iphone wcf rest