1
votes

I am using Newtonsoft.Json dll for Serialize object to return string from wcf service. 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. 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:

Message: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

1
what is your class ApplicationVM doing? is it accessing some resources? what identity is you application pool running under?Andrew
ApplicationVM is simple Entity model class which consume two entity class for BloodGroup and DayMaster.Mehul Patel
Are you able to create context class within GetData method? What credentials are you using to connect to your database? first method simply returns an constant - that has nothing to say.Andrew
yes, it works proper and also work fine with inbuilt js serialization.Mehul Patel
Will this help? under system.web <trust level="Full" /> in web.configd_z

1 Answers

1
votes

I use

<trust level="Full" />

under system.web in web.config as per @d_Z suggested and it works.