मैं पिछले 3 घंटों के लिए 100 लिंक के लिए देख रहा हूं उदाहरण के लिए webconfig में scriptfactory जोड़ना , 3 गलतियों, सामग्री प्रकार आदि सेट करनाएएसएमएक्स वेब सेवा जेसन की बजाय एक्सएमएल लौट रही है, सर्विस आउटपुट से <string xmlns = "http://tempuri.org/"> को हटाने की कोशिश कर रहा है
मैं यह समझने में सक्षम नहीं हूं कि वास्तव में गलती क्या है।
पर्यावरण: सेवा .net 4.0
आवश्यकताओं पर चल रहे .net 4.0 वेब अनुप्रयोग पर चल रहा है: मैं ASMX वेब सेवा है कि मुझे एक स्ट्रिंग के रूप एक json लौटा रहा है के साथ एक jqGrid बाध्य करने के लिए की जरूरत है। वेब सेवा फ़ाइल में निम्नलिखित कोड शामिल हैं।
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class SampleService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetJsonServerProcess()
{
int memory = 1;
string json = string.Empty;
var obj = (System.Diagnostics.Process.GetProcesses().Where(r => r.WorkingSet64 > memory).Select(p => new { p.ProcessName, p.WorkingSet64 }).ToArray());
json = Lib.ToJSON(obj);
return json;
}
}
जावास्क्रिप्ट इस प्रकार
<script type="text/javascript">
$(document).ready(function() {
jQuery("#jqgajax").jqGrid({
ajaxGridOptions: { type: "POST", contentType: 'application/json; charset=utf-8' },
url:'http://localhost:1092/SampleService.asmx/GetJsonServerProcess',
datatype: "json",
data: "{}",
colNames: ['ProcessName', 'WorkingSet64'],
colModel: [
{ name: 'ProcessName', index: 'ProcessName', width: 55 },
{ name: 'WorkingSet64', index: 'WorkingSet64', width: 90 }
],
rowNum: 10,
width: 700,
rowList: [10, 20, 30],
sortname: 'invdate',
viewrecords: true,
sortorder: "desc",
caption: "New API Example"
});
});
</script>
एचटीएमएल जब आह्वान बटन पर क्लिक के रूप में
<table id="jqgajax">
</table>
<div id="jqgajax">
</div>
वेब सेवा उत्पादन इस प्रकार है
<string xmlns="http://tempuri.org/">
[{"ProcessName":"Dropbox","WorkingSet64":22736896},
{"ProcessName":"fdhost","WorkingSet64":1941504},
{"ProcessName":"IntelliTrace","WorkingSet64":39276544}
]
</string>
कृपया सुझाव दें कि मुझे क्या याद आ रहा है। <string xmlns="http://tempuri.org/">
टैग मुझे परेशान कर रहे हैं। मुझे लगता है कि ये टैग मेरे ग्रिड को बांधने में सक्षम नहीं हैं।
अद्यतन:
ASMX सेवा अब नीचे के रूप में की तरह दिखता है। आह्वान बटन पर
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class SampleService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<demo> GetJsonServerProcess()
{
List<demo> test = new List<demo>();
for(int i=1;i<=10;i++)
test.Add(new demo { ProcessName = string.Format("Sample {0}",i), WorkingSet64 = i });
var re = test;
return re;
}
}
public class demo
{
public string ProcessName { get; set; }
public int WorkingSet64 { get; set; }
}
संभावित डुप्लिकेट: http: //stackoverflow.com/questions/11088294/asp-net-asmx-web-service-returning-xml-instead-of-json –
प्रश्न समान हैं लेकिन समाधान अलग हैं। लिंक किए गए समाधान में, फिक्स को web.config फ़ाइल को संशोधित करना था, इस समाधान में, फ़िक्स सामग्री-प्रकार शीर्षलेख को संशोधित करना है। हालांकि वे परस्पर अनन्य समाधान नहीं हो सकते हैं। – akousmata