Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Web服务总是返回混合的xml和json。如何使其成为纯json_C#_Asp.net_Json_Web Services - Fatal编程技术网

C# Web服务总是返回混合的xml和json。如何使其成为纯json

C# Web服务总是返回混合的xml和json。如何使其成为纯json,c#,asp.net,json,web-services,C#,Asp.net,Json,Web Services,我正在从事一个项目,在这个项目中,我被要求制作一个返回纯json的Web服务 我编写了这段代码,但它总是返回混合的xml和json namespace DotMeTast { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class NewsWeb

我正在从事一个项目,在这个项目中,我被要求制作一个返回纯json的Web服务

我编写了这段代码,但它总是返回混合的xml和json

namespace DotMeTast
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class NewsWebService : System.Web.Services.WebService
    {
        NewsDataContext _db = new NewsDataContext();


        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = false)]
        public string getAllNews()
        {

            var news = (from p in _db.NewsTBs
                        where p.nType == "Real"
                        select p).ToList();
            var jsonSerialiser = new JavaScriptSerializer();
            Context.Response.Clear();
            Context.Response.ContentType = "application/json";
            var json = jsonSerialiser.Serialize(news);
            return json;
        }
    }
}

关于如何使其成为纯json的任何线索

多亏了利亚姆,我做了研究,发现比webservice更好

我使用了web api,它工作正常

我找到的链接对如何在asp.net web表单中实现web api帮助很大


Web服务使用SOAP,SOAP是XML。我想你想要一个Web.API。你的意思是我应该做另一个项目Web API???Web服务通常用作通信方法(可能取决于你是否使用WCF,取决于你的确认方法等,但通常这是真的)。支持平面json(无SOAP)。SOAP是XML。如果你不想要SOAP包装器,你需要改变通信协议,不再使用SOAP。很抱歉,有没有教程我应该按照做我需要的。因为我不知道我现在该怎么办。或者你能告诉我简单的步骤吗。