2011-09-23 69 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