So I want to send a custom object to an asp.net 4.0 Webservice.
I have been sending a bunch of individual parameters but i want to start reusing some code so I'd like to do something like
[WebMethod(Description = "Testing Sending Object In")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool COT(CodeWithMessage CWM)
{
...
where the class for CodeWithMessage is
namespace UserSite
{
namespace General
{
public class CodeWithMessage
{
public int iCode { get; set; }
public string sMessage { get; set; }
public CodeWithMessage()
{
}
}
}
}
The webservice defines the input as
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<COT xmlns="http://localhost">
<CWM>
<iCode>int</iCode>
<sMessage>string</sMessage>
</CWM>
</COT>
</soap:Body>
</soap:Envelope>
I tried passing the webservice the following json
var postdata = { "iCode": -5, "sMessage": "BlogName " }
I get back an Internal Server Error [500]
{"Message":"Invalid JSON primitive: iCode."
Do I need to wrap this up somehow to indicate it is part of this object? I tried
{"__type":"UserSite.General.CodeWithMessage","iCode":-5,"sMessage":"Blog Name Already Exists"}
Which is what CodeWithMessage returns from another webservice that sends it instead of receiving it.