不知道为什么,wcf用控制台做宿主url访问不到,或者访问到了是空白的页面,但是我在程序里是有return的,求各位大神帮小弟看看是什么问题,下面是代码和访问后的页面
1 //接口 2 namespace TestWCF 3 { 4 [ServiceContract] 5 public interface IUser 6 { 7 [OperationContract] 8 [WebGet(UriTemplate = "Test",ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 9 void Test(); 10 11 12 [OperationContract] 13 [WebGet(UriTemplate = "Resp",ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 14 string Resp(); 15 } 16 }
1 namespace TestWCF 2 { 3 class Program 4 { 5 static void Main(string[] args) 6 { 7 8 Uri baseAddress = new Uri("http://localhost:9090/TestWCF"); 9 using (ServiceHost host = new ServiceHost(typeof(User),baseAddress)) 10 { 11 12 host.AddServiceEndpoint(typeof(IUser),new WSHttpBinding(), "http://localhost:9090/TestWCF/User"); 13 14 ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 15 smb.HttpGetEnabled = true; 16 host.Description.Behaviors.Add(smb); 17 18 host.Open(); 19 20 Console.WriteLine("已经开始....服务地址:\n" + baseAddress.ToString()); 21 Console.ReadKey(); 22 host.Close(); 23 } 24 } 25 } 26 }
图片看不清
大神我吧图片放大了,谢谢
@R先森: 用IIS做宿主就能访问?
访问:http://localhost:9090/TestWCF/User/Test
建议使用VS自带的WcfTestClient.exe
测试更直观