2012-11-09 83 views
0

即時通訊服務在IIS 7上託管我的WCF服務,即使它在使用WCF測試客戶端時工作正常,但我無法從簡單的控制檯應用程序中使用我的服務。IIS託管的WCF服務獲取405錯誤消耗時間

我已經允許在我的IIS上處理.svc和.wsdl文件。我不知道還有什麼我錯過了。

這裏是我的代碼:

namespace EvalServiceLibrary { 
    [ServiceContract] 
    public interface IEvalService { 
     [OperationContract] 
     void SubmitEval(Eval eval); 

     [OperationContract] 
     List<Eval> GetEvals(); 

     [OperationContract] 
     void RemoveEval(String id); 
    } 
} 

namespace EvalServiceLibrary { 
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
    public class EvalService : IEvalService { 
     #region 
     List<Eval> evals = new List<Eval>(); 

     public void SubmitEval(Eval eval) { 
      eval.Id = Guid.NewGuid().ToString(); 
      evals.Add(eval); 
     } 

     public List<Eval> GetEvals() { 
      return evals; 
     } 

     public void RemoveEval(String id) { 
      evals.Remove(evals.Find(e => e.Id.Equals(id))); 
     } 
     #endregion 
    } 
} 

而且我的web.config

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0"/> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="EvalServiceLibrary.EvalService"> 
     <endpoint address="http://localhost/WebEvalService" binding="basicHttpBinding" 
      bindingConfiguration="" name="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

這裏是我的客戶端代碼:

static void Main(string[] args) { 
      EvalServiceClient client = new EvalServiceClient(); 

      client.SubmitEval(new Eval() { Comments = "Lorem Ipsum", Submitter = "egarcia", TimeSubmitted = DateTime.Now }); 

      List<Eval> evalList = client.GetEvals().ToList(); 

      foreach(var eval in evalList) { 
       Console.WriteLine(eval.Id); 
      } 

      client.Close(); 
     } 

我可以在我的本地IIS訪問該服務的好。

+0

你可以發佈你的客戶端代碼嗎?只是連接到服務的部分。 – JcFx

+0

您可以確認您的服務是否成功激活?嘗試瀏覽URL http:// localhost/WebEvalService並查看幫助頁面。 – Praburaj

回答

0

web.config文件中存在服務端點聲明的問題。試試這個,

<service name="EvalServiceLibrary.EvalService"> 

    <!-- This endpoint is exposed at the http://localhost/EvalServiceLibrary/EvalService.svc--> 
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" name="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" /> 

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 

基本上,

  1. 您的端點地址無效。事實上,你不需要指定。

  2. 添加MexEndpoint。