WCF - 在合同列表中找不到合同名称

use*_*662 40 wcf

我对WCF比较陌生.但是,我需要创建一个向Silverlight和AJAX客户端应用程序公开数据的服务.为了实现这一目标,我创建了以下服务作为概念证明:

[ServiceContract(Namespace="urn:MyCompany.MyProject.Services")]
public interface IJsonService
{
    [OperationContract]
    [WebInvoke(Method = "GET",
               RequestFormat=WebMessageFormat.Json,
               ResponseFormat = WebMessageFormat.Json)]
    List<String> JsonFindNames();
}

[ServiceContract(Namespace="urn:MyCompany.MyProject.Services")]
public interface IWsService
{
    [OperationContract(Name="FindNames")]
    List<String> WsFindNames();
}


[ServiceBehavior(Name="myService", Namespace="urn:MyCompany.MyProject.Services")]
public class myService : IJsonService, IWsService
{
    public List<String> JsonFindNames() 
        { return FindNames(); }
    public List<String> WsFindNames()
        { return FindNames(name); }
    public List<string> FindNames()
    { 
       List<string> names = List<string>(); 
       names.Add("Alan");
       names.Add("Bill");
       return results; 
    }        
}
Run Code Online (Sandbox Code Playgroud)

当我尝试访问此服务时,收到以下错误:

在服务'myService'实现的合同列表中找不到合同名称'myService'.

这是什么原因?我该如何解决?

谢谢

Shi*_*iji 60

您的合同是接口而非实施.

在配置中的某处,您编写了myService而不是IJsonService.


小智 10

从服务名称中删除命名空间.它会工作正常.