我試圖讓我的應用程序發送數據到WCF RESTful web服務。ASIHTTPRequest + WCF POST XML
在這一點上,我沒有收到任何來自ASIHTTPRequest的錯誤消息,但Web服務沒有做任何事情。
你們可以看看它,看看你能發現什麼嗎?
的Xcode
NSURL *url = [NSURL URLWithString:@"http://www.mydomian.com/create"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSData *myPostData = [[NSString stringWithFormat:@"<Product><Description>desc1</Description><Id></Id><Name>some body</Name></Product>"] dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *myMutablePostData = [NSMutableData dataWithData:myPostData];
[request setPostBody:myMutablePostData];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request setDelegate:self];
[request startSynchronous];
Webservice的
...
公共類產品 { [數據成員] 公共字符串ID {獲得;組; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
}
...
[OperationContract的] [WebInvoke(UriTemplate = 「/創建」,方法= 「POST」,RequestFormat = WebMessageFormat.Xml,BodyStyle = WebMessageBodyStyle.Bare)] 空隙CreateProduct(產品產品);
...
... CreateProduct ...
myConnection.Open();
string insertString = "insert into tbldata (desc,Name) values (@desc,@Name)";
MySqlCommand myCommand = new MySqlCommand(insertString, myConnection);
myCommand.Parameters.Add("@desc", MySqlDbType.VarChar, 12);
myCommand.Parameters.Add("@Name", MySqlDbType.VarChar, 40);
myCommand.Parameters["@desc"].Value = product.Description;
myCommand.Parameters["@Name"].Value = product.Name;
myCommand.ExecuteNonQuery();
您是否試圖爲此請求實現委託方法?您應該收到錯誤消息,以幫助您確定問題所在。 – vfn 2011-03-01 05:21:27
setDidFinishSelector返回空的responseString。當我要求responseStatusCode時,我得到了200。 – malac 2011-03-02 03:07:44