0

我在 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 托管服务我缺少什么?

4

1 回答 1

0

您为绑定定义安全性,但从不将该绑定分配给端点:

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

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

使用该bindingConfiguration属性告诉端点使用哪个绑定配置:

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

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

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

于 2013-06-29T14:42:36.977 回答