SharePoint web服务的占位符URL
本文关键字:占位符 URL 服务 web SharePoint | 更新日期: 2023-09-27 18:00:41
tl;dr
下面是我的类库中的app.config,它简化了SharePoint中的文件操作。endpoint
地址指向任意站点,但在使用库时会动态设置为正确的站点。
如果任意地址更改/不存在,DLL还会工作吗
我是否可以打包我的类库,以便将endpoint
和binding
的动态添加到引用该库的项目中(基于它们交互的站点)?
详细信息
我在C#中创建了一个类库,以简化通过复制和列表web服务对SharePoint网站的访问。通过传入网站URL和其他数据,最终用户可以轻松地在SharePoint中上传、下载和操作文件。当他们传递网站URL时,我会动态设置"复制"或"列表"引用以使用该URL。虽然这很好,但我有两个问题:
-
我必须在app.config/web.config中包含对一个SharePoint服务器的引用,以便在开发时获取web服务的详细信息。如果该URL更改或不存在,那么我的库会失败吗?
-
即使在引用时包含DLL,也不包含包含
basicHttpBinding
和endpoint
地址的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>
谢谢你抽出时间。
我的答案
-
如果你是在App.Config中写的,它不可能是硬编码的。这是一个配置文件。您可以随时更改它,而无需重新构建项目。我希望您在继续使用功能之前先检查站点/服务器是否存在。如果服务器/站点不存在-优雅地处理它,并显示适当的消息,这样用户就可以去更改配置文件,将其指向正确的服务器
-
您可以简单地在"引用的项目"的web或app.config中添加服务所需的配置。由于DLL是在引用的项目的上下文中运行的,它将从其app/web.config 中pcik必要的值