2016-05-16 18 views
0

事情我必須做的,已經做了:主機WCF現有的MVC的Web站點

  1. 添加WCF服務到現有的MVC Web應用程序。在一些文件夾下ex:/Service/Service1.svc

  2. 將MVC站點託管到IIS,完全正常運行的站點已通過測試。

    namespace WebApplication3.Service 
    { 
        public class Service1 : IService1 
        { 
         public string DoWork() 
         { 
          return "some string"; 
         } 
        } 
    } 
    
    
    namespace WebApplication3.Service 
    { 
        [ServiceContract] 
        public interface IService1 
        { 
         [OperationContract] 
         [WebInvoke(Method = "GET")] 
         string DoWork(); 
        } 
    } 
    

和web配置:

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="transportsecurity"> 
     <security mode="Transport"> 
     <transport clientCredentialType="None"></transport> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

<services> 
    <service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior"> 
    <endpoint address="http://localhost/testsite/Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1"> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="mybehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
    multipleSiteBindingsEnabled="true" /> 

當我瀏覽服務的IIS它顯示未找到錯誤404

謝謝!

回答

1

根據您的託管方式,最有可能的端點地址不正確/匹配。

只需將端點地址更改爲空字符串。

<services> 
    <service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior"> 
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1"> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 

此外,您已將此配置爲https(傳輸安全),因此請確保您使用的是https url。對於初始測試,我建議先刪除安全性,然後使用基本綁定。一旦工作,然後測試安全性。