[英]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.