I asked this question couple of times, and I have yet to be given a good answer. May be I am doing this wrong. I would like to send one Http Post request containing some text parameters and an image. in iPhone:
NSString reqstr = "param1=val1¶m2=val2&..."
NSData *strData = [str DataUsingEncoding:NSUTF8StringEncoding]; //parameters
NSData *imageData = [NSData NSJPEGRepresenation(myImage.jpg,1)]; //image
NSMutableData *body = ...;
body.appendData = strData;
body.appendData = imageData;
req.setHttpBody = body;
In WCF:
void postData(Stream strm)
{
//strm contains "param1=val1¶m2=val2.....image raw binary here..........."
}
[DataContract]
class Employee { string param1,string param2, Stream photo..}
WCF requires opt-In serialization, so tagging a class with [DataContract] is not enough to serialize any of it's members, any member you want serialized must also be tagged with [DataMember]. Also, there's no reason for you to send the stream itself, you should be able to do something like this instead:
[DataContract]
class Employee
{
[DataMember]
string param1;
[DataMember]
string param2;
[DataMember]
JPEG image;
}
//Within your service, the postData contract will accept an Employee object from the caller // and perform some logic on it in the service.
void postData(Employee emp)
{
//Do something with emp
}
Please let me know if you have any questions or if this is more of the same advice you've already gotten.