我没有成功将NSArray发送到Web服务。
服务方法未被调用。但其他服务方法调用工作。
Web服务的方法是:如何将NSArray发送到Web服务
[WebMethod]
public int Method(IList items){...
我的数组满对象项目:
@interface Item : NSObject
{
double prop1;
double prop2;
double prop3;
}
@property double prop1;
@property double prop2;
@property double prop3;
从目标C我尝试这样发送数据:
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<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/\">"
"<soap:Body>"
"<Method xmlns=\"http://www.mysite.com/\">"
"<items>"
"%@"
"</items>"
"</Method>"
"</soap:Body>"
"</soap:Envelope>", myArray
];
NSURL *url = [NSURL URLWithString: @"http://...."];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://www.mysite.com/Method" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [NSMutableData data];
}
UPDATE
当我做数组是这样的:
NSArray * myArrDate = [NSArray arrayWithObjects:@"foo",@"bar",@"baz",nil];
而且使:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myArrDate
options:0
error:nil];
它的工作原理。 但我有一个阵列的对象User
它具有属性:UserId, FirstName, LastName, Email, Username, DisplayName, Country, City
等 当我尝试上面的代码与数组用户应用程序崩溃在该行。
和王子的答案一样。当我执行这个应用程序只是崩溃。没有任何错误。 – 1110
我已更新问题。 – 1110
好吧我发现要使用NSJSONSerialization我需要使用相同的属性创建新的类,但都是NSString的。当我这样做的时候它工作。我会接受这个答案。 – 1110