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一起發佈。 –