繁体   English   中英

SharePoint Web服务的占位符URL

[英]Placeholder URL for SharePoint web services

tl; dr

下面是我的类库中的app.config,它简化了SharePoint中的文件操作。 endpoint地址指向任意站点,但在使用库时会动态设置为正确的站点。

如果任意地址更改/停止存在,DLL仍然可以工作吗?

我可以打包我的类库以动态地向引用该库的项目添加endpoint点和binding (基于它们所交互的站点)吗?


细节

我在C#中创建了一个类库,以简化通过“复制并列出” Web服务对SharePoint网站的访问。 通过传递网站URL和其他数据,最终用户可以轻松地在SharePoint中上载,下载和操作文件。 当他们传递站点URL时,我会动态设置“复制”或“列表”引用以使用该URL。 尽管这很好,但我有两个问题:

  1. 我必须在app.config / web.config中包含对一台SharePoint服务器的引用,以在开发时获取Web服务的详细信息。 如果该URL更改或不存在,那么我的库会失败吗?

  2. 即使引用时包含DLL,也不会包含包含basicHttpBindingendpoint地址的app.config。 有没有一种方法可以将数据添加到使用类库的项目的web.config / app.config中?


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
  </appSettings>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="CopySoap" maxReceivedMessageSize="419430400">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
        <binding name="ListsSoap">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://www.example.com/subsite/_vti_bin/copy.asmx"
          binding="basicHttpBinding" bindingConfiguration="CopySoap"
          contract="CopyService.CopySoap" name="CopySoap" />
      <endpoint address="http://www.example.com/subsite/_vti_bin/Lists.asmx"
          binding="basicHttpBinding" bindingConfiguration="ListsSoap"
          contract="ListsService.ListsSoap" name="ListsSoap" />
    </client>
  </system.serviceModel>
</configuration>

谢谢你的时间。

我的答案

  1. 如果使用App.Config编写,则无法对其进行硬编码。 这是一个配置文件。 您可以随时更改它,而无需重建项目。 我希望您在继续使用功能之前先检查站点/服务器是否存在。 如果服务器/站点不存在,请妥善处理并显示适当的消息,以便用户可以更改配置文件以将其指向正确的服务器

  2. 您只需在“参考项目”的网站或app.config中添加服务所需的配置即可。 由于您的DLL在引用项目的上下文中运行,因此它将从其app / web.config中提取必要的值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM