1
所以我想发送一个自定义对象到asp.net 4.0 Webservice。
我已经发了一堆各个参数的,但我想开始重用一些代码,所以我想这样做发送自定义对象到asp.net webservice
[WebMethod(Description = "Testing Sending Object In")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool COT(CodeWithMessage CWM)
{
...
其中用于CodeWithMessage类是
namespace UserSite
{
namespace General
{
public class CodeWithMessage
{
public int iCode { get; set; }
public string sMessage { get; set; }
public CodeWithMessage()
{
}
}
}
}
web服务定义了输入作为
<?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>
我试图通过web服务下面JSON
var postdata = { "iCode": -5, "sMessage": "BlogName " }
我回来一个内部服务器错误[500]
{ “消息”: “无效JSON原始:的iCode”
我是否需要以某种方式包装它以表明它是该对象的一部分?我试过
{"__type":"UserSite.General.CodeWithMessage","iCode":-5,"sMessage":"Blog Name Already Exists"}
这是CodeWithMessage从另一个发送它的web服务返回而不是接收它。
有没有你不使用,而不是传统WCF某种原因ASMX技术? –
hrm。我想是因为我不知道WCF是如何工作的,或者它甚至取代了ASXM。我想我必须开始研究这个。谢谢 – Jordan
认真? WCF在2006年与.NET 3.0一起发布。 –