我在wcf中创建了一个web服务,其中包含OperationContract:
[OperationContract]
string getDate(string id)
然后我创建了一个客户端控制台项目,并添加了网址为“http://localhost:58536/RealWorldServices/RealWorld.svc”的服务引用,它完全有效。
但我需要在代码中绑定服务引用。我在visual studio命令提示符下使用Svcutil.exe“webservice url”命令创建“Service1.cs”。然后我将它添加到我的客户端控制台项目中。将这些代码添加到ot:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:58536/ServiceReference1.IService1.svc");
Service1Client client = new Service1Client(binding, address);
string st = client.GetData("10");
但是在最后一行与以前的方式调用方法完全相同(添加webservice方式)但我看到我收到此错误
未处理的类型异常 发生'System.ServiceModel.EndpointNotFoundException' mscorlib.dll中
附加信息:没有端点收听 http://localhost:58536/ServiceReference1.IService1.svc可以 接受消息。这通常是由不正确的地址或 SOAP动作。有关更多详细信息,请参阅InnerException(如果存在)。
答案 0 :(得分:0)
也许这可能是问题?
在您的示例中,您正在调用GetData:
string st = client.GetData("10");
但是你的合同上写着getDate
[OperationContract]
string getaDate(string id)
我相信在服务中创建的默认方法之一是GetData,它接受int
。