简体   繁体   English

为什么我不能在wcf服务中使用Newtonsoft.Json JsonConvert.SerializeObject?

[英]Why I can't use Newtonsoft.Json JsonConvert.SerializeObject in wcf service?

I am using Newtonsoft.Json dll for Serialize object to return string from wcf service. 我正在使用Newtonsoft.Json dll进行序列化对象以从wcf服务返回字符串。 When I call other simple method from service it works fine but when I call method which serialize object into string and return that string its not working. 当我从服务调用其他简单方法时,它可以正常工作,但是当我调用将对象序列化为字符串并返回该字符串的方法时,它将无法正常工作。 Below is my code of service. 以下是我的服务代码。

public string GetString()
    {
        return "Hello";
    }

    public string GetData(int i)
    {
        My_Entities ME = new MY_Entities();

        ApplicationVM oVM = new ApplicationVM()
        {
            AP_M_BloodGroup = ME.AP_M_BloodGroup.ToList().ElementAtOrDefault(i),
            AP_M_DayMaster = ME.AP_M_DayMaster.ToList().ElementAtOrDefault(i)
        };
        return JsonConvert.SerializeObject(oVM, Formatting.Indented);
    }

Both method work for local but after hosting when calling GetData() method it will give error message "Access Denied" at client side. 两种方法都适用于本地,但是在托管时调用GetData()方法后,它将在客户端给出错误消息"Access Denied" So, what is the problem and what I need to put extra? 那么,问题是什么,我需要补充些什么?

When I put client side code in try-catch block it gives message like: 当我将客户端代码放在try-catch块中时,它给出如下消息:

Message: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed 消息:请求类型为“ System.Security.Permissions.SecurityPermission,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089”的权限失败

I use 我用

<trust level="Full" />

under system.web in web.config as per @d_Z suggested and it works. 根据@d_Z建议在web.config中的system.web下,它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Newtonsoft.Json C# :: 格式化 JsonConvert.SerializeObject - Newtonsoft.Json C# :: Formatting JsonConvert.SerializeObject NewtonSoft JsonConvert.SerializeObject中的MaxJsonLength错误 - MaxJsonLength error in NewtonSoft JsonConvert.SerializeObject Newtonsoft.Json.JsonReaderException:在 JsonConvert.SerializeObject 之后解析 JsonConvert.DeserializeObject 时遇到意外字符 - Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing on JsonConvert.DeserializeObject after JsonConvert.SerializeObject JsonConvert.SerializeObject与json_encode - JsonConvert.SerializeObject vs json_encode JsonConvert.SerializeObject(本); 在JSON中呈现函数的结果 - JsonConvert.SerializeObject(this); to render the results of a function in the JSON JsonConvert.SerializeObject()导致JSON格式错误 - JsonConvert.SerializeObject() causing JSON to be malformed 使用JsonConvert.SerializeObject创建Json结构 - Create Json structure using JsonConvert.SerializeObject NewtonSoft JsonConvert.SerializeObject, \" 在序列化 DateTime 后添加 - NewtonSoft JsonConvert.SerializeObject, \" added after serializing DateTime 如果名称为大写字母,Newtonsoft JsonConvert.SerializeObject会忽略JsonProperty - Newtonsoft JsonConvert.SerializeObject ignoring JsonProperty if name is uppercase Newtonsoft.Json Json转换为数据表 - Newtonsoft.Json JsonConvert To Datatable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM