好像碰上了服务端点试图从我的服务来获取时,没有发现问题。
如果我尝试的http://本地主机:8000 / hello /的帮助我应该会看到<字符串>您进入帮助<字符串>
但我只拿到了没有终点呢?我还没有摸着我的配置文件在所有和我只是从一个控制台应用程序托管。
主持人:
命名空间的主机
{
类节目
{
静态无效的主要(字串[] args)
{
的WebHttpBinding绑定=新的WebHttpBinding();
WebServiceHost主机=
新WebServiceHost(typeof运算(服务1));
host.AddServiceEndpoint(typeof运算(IService1)
结合,
HTTP://本地主机:8000 /你好);
host.Open();
Console.WriteLine(你好世界服务);
Console.WriteLine(preSS<返回>至服务端);
到Console.ReadLine();
}
}
}
服务1:
命名空间WcfServiceLibrary1
{
//注意:您可以使用重命名命令中的重构菜单上改变这两个code和配置文件一起在类名服务1。
公共类服务1:IService1
{
公共字符串的GetData(字符串值)
{
返回的String.Format(您输入:{0},值);
}
IService1:
[的ServiceContract]
公共接口IService1
{
[WebGet(UriTemplate =/ {}值)]
字符串的GetData(字符串值);
解决方案
删除从{}值的/,并确保它被列为 OperationContract的
。它应该是:
[WebGet(UriTemplate ={}值)]
[OperationContract的]
基本URL将通过与结尾的斜线,让你真正需要的的http://本地主机:8000 /你好//帮助
在目前的code
Seem to run into a service endpoint not found problem when trying to get from my service.
if I try http://localhost:8000/hello/help I should expect to see <string>You entered help <string>
but I only get the no endpoint instead? I havent touched my config files at all and I am just hosting from a console app.
Host:
namespace Host
{
class Program
{
static void Main(string[] args)
{
WebHttpBinding binding = new WebHttpBinding();
WebServiceHost host =
new WebServiceHost(typeof(Service1));
host.AddServiceEndpoint(typeof(IService1),
binding,
"http://localhost:8000/hello");
host.Open();
Console.WriteLine("Hello world service");
Console.WriteLine("Press <RETURN> to end service");
Console.ReadLine();
}
}
}
Service1:
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
IService1:
[ServiceContract]
public interface IService1
{
[WebGet(UriTemplate = "/{value}")]
string GetData(string value);
解决方案
Remove the / from {value} and make sure it is listed as an OperationContract
. It should be:
[WebGet(UriTemplate = "{value}")]
[OperationContract]
The base URL will come through with the trailing slash, so you are really looking for http://localhost:8000/hello//help
in the current code