【发布时间】:2014-05-30 14:14:59
【问题描述】:
using System.ServiceModel;
namespace helloserviceDemo2
{
[ServiceContract]
interface IHelloService
{
[OperationContract]
string sayHello(string name);
}
class HelloService : IHelloService
{
public string sayHello(string name)
{
return name + " welcome";
}
}
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(HelloService));
BasicHttpBinding httpBinding = new BasicHttpBinding();
host.AddServiceEndpoint(typeof(IHelloService), httpBinding, "http://localhost:8080/helloservice");
host.Open();
Console.WriteLine("service is running now");
Console.ReadKey();
}
}
}
当我运行这个应用程序时,它运行良好。但是这个网址没有得到服务。请帮助我摆脱这个问题。谢谢
【问题讨论】:
-
"url is not getting with service" 您能详细说明一下,您是否收到错误消息、超时或其他什么?能否请您提供有关您如何访问该服务的详细信息。
-
没有得到什么?相处不来?
-
也许可以尝试在 ServiceHost 构造函数中添加一个基地址,如下所示:ServiceHost host = new ServiceHost(typeof(HelloService), new Uri("localhost:8080"))
-
碰巧你没有运行一个运行 IIS 并捕获端口的操作系统,是吗?