views:

34

answers:

1

I need to call a web service to receive a JSON object which I'll parse before rendering the content. Here's the code for the same:

Dim jResponse As MessageResponseWrapper = New MessageResponseWrapper() 'Custom class to deserialize JSON
        Dim req As System.Net.HttpWebRequest
        req = System.Net.WebRequest.Create("http://some-cross-domain?q=" & SearchKeyword & "&restapi.response_style=view&xslt=json.xsl")
        req.Method = WebRequestMethods.Http.Get
        Dim res As HttpWebResponse = req.GetResponse()
        Dim reader As New StreamReader(res.GetResponseStream())
        Dim json As String = reader.ReadToEnd()

        Dim ser As New DataContractJsonSerializer(GetType(MessageResponseWrapper))
        Using ms As New MemoryStream(Encoding.Unicode.GetBytes(json))
            jResponse = TryCast(ser.ReadObject(ms), MessageResponseWrapper)
        End Using

This works as a stand alone ASP.Net page. However, I need this as a Web Part to port to a Sharepoint site. Using the method described here I've given the above code in the RenderControl() method. I get the error "The "CustomWebPart" Web Part appears to be causing a problem. Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

I have tried including variations of the following line in web.config with no avail.

<SafeControl Assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Net" TypeName="WebPermission" Safe="True" AllowRemoteDesigner="True" />

Any ideas?

A: 

Deploying the webpart to GAC worked. I was deploying it manually before - copy dll to bin folder

Deploying to GAC give permissions to make calls like WebRequest.Create()

Sharepoint Security references: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/sharepoint_wsscodeaccesssecurity.asp

LVS