Hi, I know there are questions on here asking exactly the same thing, but despite me reading them I'm still missing something and hopefully you can help!
It's very simple, using the WCF template that is added by VS!
Interface:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat= WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
CompositeType GetDataUsingDataContract(CompositeType composite);
Implementation:
public CompositeType GetDataUsingDataContract(CompositeType composite){
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
Javascript:
$.ajax({
type: "POST",
url: "http://localhost:1545/Service1.svc/GetDataUsingDataContract",
data: JSON.stringify(compType),
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
success: function (msg) {
$("#txtTest").val(message.BoolValue + " : " + message.StringValue);
},
error: function (xhr, errorMsg, thrown) {
$("#error").html(xhr.responseText);
}
});
The error I get is: The server encountered an error processing the request. The exception message is 'Value cannot be null. Parameter name: composite'.
So the value is not being passed, its null when it gets to the WCF service.
*Note: I have tried calling methods that take a string and return the composite type, that works fine *
Thx in advance for your help