2011-09-23 71 views
1

我想弄清楚WCF服務。我有1次工作1次,現在我似乎無法得到這個工作(甚至遵循前面的例子)。我不明白關於WCF服務的幾件事。例如,爲什麼它需要端點。他們的服務目的是什麼?但是,如果有人能幫助我解決這個錯誤,那就太好了。初學者WCF服務設置

我想設置一個默認的WCF服務。我沒有添加任何代碼。我只是試圖讓服務顯示。

我pilltrakr.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace serviceContract 
{ 
    public class pilltrakr : Ipilltrakr 
    { 
     public void DoWork() 
     { 
     } 
    } 
} 

我有Ipilltrakr:

namespace serviceContract 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "Ipilltrakr" in both code and config file together. 
    [ServiceContract] 
    public interface Ipilltrakr 
    { 
     [OperationContract] 
     void DoWork(); 
    } 
} 

我:pilltrakr.svc

<%@ ServiceHost Language="C#" Debug="true" Service="pilltrakr" CodeBehind="~/App_Code/pilltrakr.cs" %> 

在我的web.config我有以下幾點:

<system.serviceModel> 
    <services> 
     <service name="serviceContract.pilltrakr" behaviorConfiguration="InternalWebService"> 
     <endpoint contract="serviceContract.Ipilltrakr" binding="basicHttpBinding" address="pilltrakr" 
bindingConfiguration="InternalHttpBinding" bindingNamespace="serviceContract"/> 
     </service> 
    </services> 
    </system.serviceModel> 

,我發現了以下錯誤:

Server Error in '/pilltrakr' Application. The type 'pilltrakr', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type 'pilltrakr', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

回答

4

您需要在您的.svc文件,包括命名空間指定服務類的確切名稱:至於你有關端點的問題

<%@ ServiceHost 
    Language="C#" 
    Debug="true" 
    Service="serviceContract.pilltrakr" 
    CodeBehind="~/App_Code/pilltrakr.cs" 
%> 

關心的是,它們被用來定義服務將在什麼地址響應以及它將使用什麼綁定。例如,您可以在兩個不同的端點上暴露您的服務=>使用SOAP和其他使用REST的服務。

+1

現在好了,我覺得比以前更愚蠢了...謝謝你,你的回答很有效。 – webdad3