3
契约类型HelloIndigo.Service不归属于 ServiceContractAttribute。为了定义有效的合同,指定类型(合约界面或服务类别)必须为 ,且归属于ServiceContractAttribute。当调用一个服务时,我得到一个InvalidOperationException
我构建一个库类并引用控制台应用程序中的类。
图书馆类:
namespace HelloIndigo
{
public class Service : IHelloIndigoService
{
public string HelloIndigo()
{
return "Hello Indigo";
}
}
[ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
interface IHelloIndigoService
{
[OperationContract]
string HelloIndigo();
}
}
控制台应用程序:
namespace Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.Service),
new Uri("http://localhost:8000/HelloIndigo")))
{
host.AddServiceEndpoint(typeof(HelloIndigo.Service),
new BasicHttpBinding(),"Service");
host.Open();
Console.WriteLine("Press enter to terminate the host service");
Console.ReadLine();
}
}
}
}
请支付一些注意你的问题的格式。在写问题时有一个预览,在发布之前查看它。 (我已经为你解决了这个问题)。 – 2012-01-07 19:06:10