WCF托管在SharePoint上-需要启用https [英] WCF hosted on SharePoint - Need to enable https

查看:48
本文介绍了WCF托管在SharePoint上-需要启用https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a WCF hosted in SharePoint 2013 with two methods GET and SET send JSON data. The WCF worked fine under HTTP servers but now we need to move it to production and run it under SSL where we have a certificate installed on the server. I made changes to the web.config file but I'm getting error 404 Not Found when I try to call the GET method.

这是我的Web.Config(更改之前在HTTP上工作)

Here is my Web.Config (working on HTTP before the change)

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

这是我试图使代码正常工作的地方:

Here is what I tried to make the code work:

<?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#代码:

Here is my C# Code on the service interface:

 [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托管服务启用此方法?

Any Ideas? What am I missing to enable this method on HTTPS as a SharePoint ISAPI hosted service?

推荐答案

您为绑定定义安全性,但是您从未分配该绑定到您的端点:

You define security for your binding, but you never assign that binding to your endpoint:

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

您的所有服务端点都说使用 webHttpBinding -因为您没有为绑定指定配置,所以使用默认设置,而 webHttpBinding 的默认传输方式是.

All your service endpoint says is use webHttpBinding - since you didn't specify a configuration for the binding, the defaults are used, and the default transport for webHttpBinding is None.

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

Use the bindingConfiguration attribute to tell the endpoint which binding configuration to use:

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

如果要为其添加安全性,建议将配置名称更改为"NoSecurityHttpBinding"以外的其他名称.

I'd suggest changing the name of your configuration to something other than "NoSecurityHttpBinding" if you're adding security to it.

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

There may be other issues as well, but you won't even get out of the door until you assign the binding configuration to your endpoint.

这篇关于WCF托管在SharePoint上-需要启用https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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