我正在尝试http://therelentlessfrontend.com/2010/05/11/basic-wcf-tutorial-for-beginners/的WCF,但我的连接有问题。这是我的代码
接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
namespace Service
{
[ServiceContract(Namespace = "")]
public interface IOperation
{
[OperationContract]
string HelloWorld();
}
}
实施
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Service
{
class ImplOperation : IOperation
{
public string HelloWorld()
{
return "Hello world";
}
}
}
主机服务
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace Service
{
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("Http://localhost:8000/Service");
using (ServiceHost sHost = new ServiceHost(typeof(ImplOperation),baseAddress))
{
try
{
sHost.AddServiceEndpoint(typeof (IOperation), new WSHttpBinding(), "ImplOperation");
ServiceMetadataBehavior sBehaviour = new ServiceMetadataBehavior() {HttpGetEnabled = true};
sHost.Description.Behaviors.Add(sBehaviour);
sHost.Open();
Console.WriteLine("Service started");
Console.WriteLine("press <Enter> to close");
Console.ReadLine();
sHost.Close();
}catch(Exception exception)
{
Console.WriteLine("Exception:\t {0}",exception.Message);
sHost.Abort();
}
}
}
}
}
现在当我运行svcutil.exe时出现错误
c:\Users\lakpa\My Documents\visual studio 2010\Projects\WcfConsoleService\Client
>svcutil.exe /language:cs /out:GeneratedProxy.cs /config:app.config Http://local
host:8000/Service/ImplOperation
HTTP GET Error
URI: http://localhost:8000/Service/ImplOperation
There was an error downloading 'http://localhost:8000/Service/ImplOperation'
.
The request failed with HTTP status 400: Bad Request.
If you would like more help, type "svcutil /?"
当我创建Uri的实例时,uri name = service是可选的,所以它必须与namesapce名称相同或者我可以写任何东西,当我添加serviceEndpoint时,那个名称“ImplOperation”,可以我在那里写什么?