简体   繁体   中英

Placeholder URL for SharePoint web services

tl;dr

Below is the app.config from my class library which simplifies file manipulation in SharePoint. The endpoint addresses point at an arbitrary site but are set dynamically to the correct site when the library is used.

Will the DLL still work if the arbitrary address changes/ceases to exist?

Can I package my class library to dynamically add endpoint 's and binding 's to the project that references the library (Based on the site they interact with)?


Details

I created a class library in C# to simplify access to SharePoint sites via the Copy and Lists web services. By passing in the site URL and other data, the end user can easily upload, download, and manipulate files in SharePoint. When they pass the site URL, I dynamically set the Copy or Lists reference to use that URL. While this works out fine, I have two questions:

  1. I must include a reference in the app.config/web.config to one SharePoint server to get the web service details when developing. If that URL changes or ceases to exist, then will my library fail?

  2. Even though the DLL is included when referenced, the app.config containing the basicHttpBinding and endpoint addresses is not included. Is there a way to add that data in the web.config/app.config of the project that is using the class library?


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

Thanks for your time.

My Answers

  1. If you are writing it in App.Config, there is no way it's hard coded. It's a config file. You can change it whenever you want and you do not need to rebuild your project. I hope for you are checking wheather the Site/Server exists before proceeding with functionality. If the server/site does not exist - handle it gracefully and show appropiate message so that a user can go and change the config file to point it to correct server

  2. You can simply add the configs required for your service in the "Referenced Project"'s web or app.config. Since your DLL in running in the context of the Referenced Project, it would pcik the necessary values from its app/web.config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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