添加Web服务绑定到使用SPWebConfigModification的SharePoint的web.config [英] Adding web service bindings into SharePoint web.config using SPWebConfigModification

查看:161
本文介绍了添加Web服务绑定到使用SPWebConfigModification的SharePoint的web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用WCF服务的SharePoint Web部件。为了能够使用的Web服务在我的网络的一部分,我需要修改的SharePoint web.config中包括绑定点和结束点。

I have a SharePoint web part which uses a WCF service. To be able to consume the web service in my web part, I need to modify the SharePoint web.config to include bindings and end points.

什么是做到这一点的最好方法是什么?

What's the best way to do this?

推荐答案

要能够做到这一点,我把我的Web服务配置到一个文本文件作为模板。该文本文件(BindingTemplate.txt)内容如下:

To be able to do this, I put my web service configuration into a text file as a template. The text file (BindingTemplate.txt) content is as the following:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_AuthenticationInterface" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://{0}/MyWebService/AuthenticationService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_AuthenticationInterface" contract="AuthenticationService.AuthenticationInterface" name="BasicHttpBinding_AuthenticationInterface" />
</client>

我用C#以下code修改Web.config:

I used the C# following code to modify the web.config:

string content;
string WebServiceServer = "example.com"; // <=== your host-name here
using (TextReader tr = File.OpenText(bindingFilePath))
{
    content = String.Format(tr.ReadToEnd(), WebServiceServer);
}

SPWebConfigModification modification = new SPWebConfigModification("system.serviceModel", "configuration");
modification.Value = content;
modification.Sequence = 0;
modification.Type =SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Owner = OWNER_CONSTANT;

webApp.WebConfigModifications.Add(modification);

我花了一些时间计算出来。希望这将帮助别人。

I spent some time figuring it out. Hope this will help someone.

这篇关于添加Web服务绑定到使用SPWebConfigModification的SharePoint的web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆