0

tl;博士

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

如果任意地址更改/停止存在,DLL 是否仍然有效?

我可以打包我的类库以将endpoint's 和binding's动态添加到引用该库的项目中(基于他们与之交互的站点)吗?


细节

我在 C# 中创建了一个类库,以简化通过 Copy and Lists Web 服务访问 SharePoint 网站的过程。通过传入站点 URL 和其他数据,最终用户可以轻松地在 SharePoint 中上传、下载和操作文件。当他们传递站点 URL 时,我动态设置 Copy 或 Lists 引用以使用该 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>

谢谢你的时间。

4

1 回答 1

1

我的答案

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

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

于 2013-02-22T11:06:43.600 回答