0

我在从沙盒 Visual Web Part Sharepoint 2010 调用 Azure WCF 服务时遇到问题。所有本地计算机都安装了 Windows 7 64 Ultimate - Sharepoint Foundation 2010 以使用 Azure SDK 开发 Web 部件和 Visual Studio 2010。在本地 Azure 模拟器中启动的 Web 服务,本地计算机中的 Web 部件。当我使用标准主“添加服务引用”到 Web 部件时,生成 app.config,然后抛出错误:

 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, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限。

app.config 网页部分:

<?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>

PS 当所有移动到工作部署 - Azure и Sharepoint Online - 再次出错。我以编程方式创建连接,因为读取,在沙盒解决方案 app.config 中未使用 Web 部件部署,我们必须在 web.config Sharepoint 2010 中复制他的代码 - 但在 Sharepoint Online 中,此文件已向开发人员关闭!

4

2 回答 2

0

您从 SharePoint 请求中收到“System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型权限的正确错误。 这是因为沙盒限制。您可以从这篇MSDN 文章中查看沙盒代码被拒绝的所有权限。和 WebPermission 以及 SocketPermission 一起用于沙盒解决方案中的代码。

如果你想访问外部服务,不管是使用 TCP 还是 HTTP 协议,你都应该转向完全信任的解决方案。

于 2012-12-07T10:20:10.827 回答
0

我首先验证了您确实可以使用 SharePoint Designer 2010 创建一个外部内容类型,该内容类型使用 SQL Server 并将数据写入 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 部件,因为沙盒解决方案不支持进行出站 Web 调用.

你验证了最后一部分吗?

于 2012-05-02T07:39:38.837 回答