在SharePoint上托管的WCF - 需要启用https

时间:2013-06-28 19:51:52

标签: wcf sharepoint https

我在SharePoint 2013中托管了一个WCF,其中有两个方法GET和SET发送JSON数据。 WCF在HTTP服务器下运行良好,但现在我们需要将其移至生产环境并在SSL下运行,我们在服务器上安装了证书。 我对web.config文件进行了更改,但是当我尝试调用GET方法时,我收到错误404 Not Found。

这是我的Web.Config(在更改之前处理HTTP)

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
  <service name="WCF.Service" behaviorConfiguration="WCF.ServiceBehavior" >
    <endpoint address=""
        binding="webHttpBinding"
        contract="WCF.IService"
              />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WCF.ServiceBehavior">
      <serviceMetadata  httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior >
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="NoSecurityHttpBinding">
      <security mode="None">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

以下是我尝试使代码工作的内容:

<?xml version="1.0"?>
<configuration>
<system.serviceModel>

<services>
  <service name="WCF.Service" behaviorConfiguration="WCF.ServiceBehavior" >
    <endpoint address=""
        binding="webHttpBinding"
        contract="WCF.IService"
              />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WCF.ServiceBehavior">
      <serviceMetadata  **httpsGetEnabled**="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior >
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="NoSecurityHttpBinding">
      <security mode="**Transport**">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

这是我在服务界面上的C#代码:

 [ServiceContract]
 public interface IService
 {
    [OperationContract]
    [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Get/{Code}")]
    Stream Get(string Code);

}

方法代码

public class Service : IService
{

    public Stream Get(string Code)
    {
        string strOutPut = "";
        WebOperationContext.Current.OutgoingResponse.ContentType = "application/json;charset=utf8";
        try
        {
            /// geting data
            return new MemoryStream(Encoding.UTF8.GetBytes(strOutPut));
        }
        catch (Exception e)
        {
           // error handler
        }
    }
}

任何想法?在HTTPS上作为SharePoint ISAPI托管服务启用此方法我缺少什么?

1 个答案:

答案 0 :(得分:0)

您可以为绑定定义安全性,但绝不会指定绑定到您的终端:

<service name="WCF.Service" behaviorConfiguration="WCF.ServiceBehavior" >
  <endpoint address=""
            binding="webHttpBinding"
            contract="WCF.IService" />
  </service>

所有服务端点都使用webHttpBinding - 因为您没有为绑定指定配置,所以使用默认值,webHttpBinding的默认传输为None

使用bindingConfiguration属性告诉端点要使用哪种绑定配置:

<endpoint address=""
          binding="webHttpBinding"
          bindingConfiguration="NoSecurityHttpBinding"
          contract="WCF.IService" />

如果您要为其添加安全性,我建议您将配置名称更改为“NoSecurityHttpBinding”以外的其他名称。

也可能存在其他问题,但在将绑定配置分配给端点之前,您甚至都不会出门。