2013-06-28 67 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