2013-06-28 29 views
0

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

这里是我的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托管服务启用的问题?

回答

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”其他的东西,如果你要添加的安全吧。

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

+0

谢谢..这工作 – user2533118