我有一个关于' AddServiceEndpoint'的使用的问题' ServiceHost'的方法类。 似乎在“地址”中添加了一个值。此方法的参数部分不起作用。
请参阅以下代码摘录:
Uri httpUrl = new Uri("http://localhost:8090/DuplexServer/SimpleCalculator");
host.AddServiceEndpoint(typeof(DuplexServer.ICalculatorDuplex), new WSDualHttpBinding(), "");
在这里,为了测试,我可以通过Web浏览器访问此URL:
http://localhost:8090/DuplexServer/SimpleCalculator
和网页已成功显示。
但是,如果我以这种方式实现它:
Uri httpUrl = new Uri("http://localhost:8090/DuplexServer/");
host.AddServiceEndpoint(typeof(DuplexServer.ICalculatorDuplex), new WSDualHttpBinding(), "SimpleCalculator");
当我访问:http://localhost:8090/DuplexServer/SimpleCalculator
时,会出现一个空白页。
该方法正在主机项目的文件中运行,该文件是一个控制台应用程序。 要求的整个代码:
class Program
{
static void Main(string[] args)
{
//Create a URI to serve as the base address
Uri httpUrl = new Uri("http://localhost:8090/DuplexServer/SimpleCalculator");
//Create ServiceHost
ServiceHost host = new ServiceHost(typeof(DuplexServer.CalculatorService), httpUrl);
//Add a service endpoint
host.AddServiceEndpoint(typeof(DuplexServer.ICalculatorDuplex), new WSDualHttpBinding(), "");
//Enable metadata exchange
/*
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
*/
//Start the Service
host.Open();
Console.WriteLine("Service is host at " + DateTime.Now.ToString());
Console.WriteLine("Host is running... Press <Enter> key to stop");
Console.ReadLine();
}
}
我想知道使用&#39;地址&#39;的正确方法。这个方法的参数。
感谢。