2012-04-16 77 views
0

我有問題可以從沙盒Visual Web Part Sharepoint 2010調用Azure WCF服務。所有安裝的本地計算機Windows 7 64 Ultimate - Sharepoint Foundation 2010用於開發Web部件和帶有Azure SDK的Visual Studio 2010。 Web Service從本地Azure模擬器啓動,Web部件在本地計算機中啓動。 當我使用非標準大師「添加服務引用」,以Web部件,生成的app.config,則拋出錯誤:Azure WCF服務+ Sharepoint 2010沙盒Visual Web部件=錯誤

ServiceReference1.Service1Client serv = new ServiceReference1.Service1Client(); 
Label1.Text = serv.GetData(9); 

找不到,在ServiceModel引用合同「ServiceReference1.IService1」默認終結點元素客戶端配置部分。 這可能是因爲沒有爲您的應用程序找到配置文件,或者是因爲在客戶端元素中找不到匹配此合同的端點元素。

當我創建連接編程 -

EndpointAddress adr = new EndpointAddress(new Uri("http://127.0.0.1:81/Service1.svc")); 
BasicHttpBinding basic = new BasicHttpBinding(); 
ChannelFactory<ServiceReference1.IService1Channel> fact = new ChannelFactory<ServiceReference1.IService1Channel>(basic, adr); 
Label1.Text = fact.CreateChannel().GetData(8); 

扔錯誤:

請求類型的「System.Net.WebPermission,系統權限,版本= 2.0.0.0,文化=中性,PublicKeyToken = b77a5c561934e089「。

的app.config的WebPart:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IService1" /> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://127.0.0.1:81/Service1.svc" binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
       name="BasicHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

的web.config Azure的WCF服務:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    </configSections> 
    <!-- To collect diagnostic traces, uncomment the section below or merge with existing system.diagnostics section. 
     To persist the traces to storage, update the DiagnosticsConnectionString setting with your storage credentials. 
     To avoid performance degradation, remember to disable tracing on production deployments. 
    <system.diagnostics>  
    <sharedListeners> 
     <add name="AzureLocalStorage" type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"/> 
    </sharedListeners> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing"> 
     <listeners> 
      <add name="AzureLocalStorage"/> 
     </listeners> 
     </source> 
     <source name="System.ServiceModel.MessageLogging" switchValue="Verbose"> 
     <listeners> 
      <add name="AzureLocalStorage"/> 
     </listeners> 
     </source> 
    </sources> 
    </system.diagnostics> --> 
    <system.diagnostics> 
    <trace> 
     <listeners> 
     <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      name="AzureDiagnostics"> 
      <filter type="" /> 
     </add> 
     </listeners> 
    </trace> 
    </system.diagnostics> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

附:當所有人都轉到工作部署時 - Azure和Sharepoint Online - 再次出現錯誤。我以編程方式創建連接,因爲閱讀,在沙盒 解決方案app.config未與Web部件一起部署,我們必須在web.config Sharepoint 2010中複製他的代碼 - 但在Sharepoint Online中,此文件已從開發者處關閉!

回答

0

我首先驗證了您確定可以使用SharePoint Designer 2010創建一個外部內容類型,該類型將數據寫入SQL Server,Windows Communication Foundation(WCF)服務或.NET類型。

Next SharePoint BCS支持SOAP和OData,但WCF數據服務支持OData服務,因此要使用WCF數據服務,需要OData基礎連接。數據視圖Web部件可以發出適用於OData提要的GET請求。

SharePoint Online Office 365支持沙盒解決方案,這意味着.Net/C#代碼和解決方案部署的Web部件是可能的,但是我不確定是否可以按照您描述的方式連接SP Web部件,因爲沙盒解決方案不支持使出站的網絡電話。

你是否驗證了最後一部分?

0

您收到來自SharePoint的正確錯誤 請求「System.Net.WebPermission,System,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089」類型的權限。 這是因爲沙盒限制。您可以從this MSDN文章中看到拒絕沙箱代碼的所有權限。 WebPermission和SocketPermission一起用於沙盒解決方案中的代碼。

如果您想訪問外部服務,使用TCP或HTTP協議無關緊要,您應該轉向完整的信任解決方案。

相關問題