User-330142929 posted
Hi msdevtech,
As far as I know, we could use the xmlserializer to serialize object and return xml string in order to attached to the payload, for Json, we use the JavaScriptSerializer by default.
public static string Call(BookInfo input)
{
string serviceUrl = "http://ws-abrahamq-01:90/Service1.svc/booking";
StringBuilder sb = new StringBuilder();
//BookInfo p = new BookInfo()
//{
// Name = "abcd"
//};
XmlSerializer serializer = new XmlSerializer(typeof(BookInfo));
TextWriter tw = new StringWriter(sb);
serializer.Serialize(tw, input);
//string stringPayload = "{\"bookInfo\":" + JsonConvert.SerializeObject(input) + "}";
string stringPayload1 = sb.ToString();
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(serviceUrl);
request.ContentType = "application/json";
request.Method = "POST";
byte[] body = Encoding.UTF8.GetBytes(stringPayload1);
request.ContentLength = body.Length;
request.GetRequestStream().Write(body, 0, body.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string content = reader.ReadToEnd();
response.Close();
reader.Close();
request.Abort();
response.Close();
return content;
}
}
[DataContract]
public class BookInfo
{
[DataMember]
public string Name { get; set; }
}
I suggest you could post your code so that I could restore your problem with SOAPUI and give you an effective reply.
Feel free to let me know if you have any questions.
Best Regards
Abraham