WCF - 在合同列表中找不到合同名称 [英] WCF - Contract Name could not be found in the list of contracts
问题描述
我对 WCF 比较陌生.但是,我需要创建一个向 Silverlight 和 AJAX 客户端应用程序公开数据的服务.为了实现这一目标,我创建了以下服务作为概念证明:
I am relatively new to WCF. However, I need to create a service that exposes data to both Silverlight and AJAX client applications. In an attempt to accomplish this, I have created the following service to serve as a proof of concept:
[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;
}
}
当我尝试访问此服务时,收到以下错误:
When I try to access this service, I receive the following error:
在服务myService"实现的合同列表中找不到合同名称myService".
The contract name 'myService' could not be found in the list of contracts implemented by the service 'myService'.
这是什么原因?我该如何解决这个问题?
What is the cause of this? How do I fix this?
谢谢
推荐答案
你的契约是接口而不是实现.
Your contract is the Interface not the implementation.
您在配置中的某处编写了 myService 而不是 IJsonService.
Somewhere in the config you have written myService instead of IJsonService.
这篇关于WCF - 在合同列表中找不到合同名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!