0
votes

I'm trying to make my app send data to a WCF RESTful webservice.

At this point I'm not getting any error message from ASIHTTPRequest but the web service not doing anything either.

Could you guys take a look at it and see if you can spot something?

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

...

public class Product { [DataMember] public string Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public string Description { get; set; }
}

...

[OperationContract] [WebInvoke(UriTemplate = "/create", Method = "POST", RequestFormat=WebMessageFormat.Xml, BodyStyle=WebMessageBodyStyle.Bare)] void CreateProduct(Product product);

...

...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();
1
Have you tried to implement the delegate methods for this request? You should get error messages that will help you identify where the issue is.vfn
setDidFinishSelector returns empty responseString. When I asked for responseStatusCode I got returned 200.malac

1 Answers

0
votes

Your request looks okay to me, but you could try testing it with another tool, like curl from the command line to be sure. Here's something to try:

curl -D headers.txt -X POST -H 'Content-Type:application/xml' -d '<Product><Description>desc1</Description><Id></Id><Name>somebody</Name></Product>' http://www.mydomain.com/create

Check stdout for the response body and headers.txt for the response headers. You should get the same thing you're getting in your iOS app.

In terms of the server-side response, try responding with a different status code or body.