2010-09-20 41 views
0

我需要調用Web服務來接收JSON對象,我將在呈現內容之前解析它。這裏的代碼相同:對WebParts使用RenderControl()內部的WebRequest.Create

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 

這可以作爲一個獨立的ASP.Net頁面。但是,我需要將此作爲Web部件移植到Sharepoint站點。使用描述的方法here我已經在RenderControl()方法中給出了上述代碼。我收到錯誤「The CustomWebPart」Web Part似乎出現問題,請求「System.Net.WebPermission,System,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089」類型的權限失敗。

我已經嘗試過在web.config中包含以下行的變體,但無濟於事。

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

任何想法?

+0

你部署和激活網絡部分在您的SharePoint安裝? – 2010-09-20 16:16:18

+0

只要將Web部件分配給頁面,我就會收到錯誤消息。是的,它填充在Webpart畫廊 – 2010-09-21 03:55:37

+0

我認爲這是因爲它跨域調用。任何方式呢? – 2010-09-22 11:05:52

回答