积极答复者
我的宿主程序是这么写的,为什么不能通过浏览器查看元数据啊?

问题
-
我的宿主程序是这么写的,为什么不能通过浏览器查看元数据啊?
using System; using System.ServiceModel; using System.ServiceModel.Description; using MyContract; using MyService; namespace HosterConsoleApp { class Program { static void Main(string[] args) { Uri baseAddress = new Uri("http://localhost:9001/Calculator"); using(ServiceHost host = new ServiceHost(typeof(Calculator), baseAddress)) { BasicHttpBinding binding = new BasicHttpBinding(); host.AddServiceEndpoint(typeof(ICalculator), binding, String.Empty); ServiceMetadataBehavior behavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (behavior == null) { behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; behavior.HttpGetUrl = baseAddress; host.Description.Behaviors.Add(behavior); } else { behavior.HttpGetEnabled = true; behavior.HttpGetUrl = baseAddress; } host.Opening += delegate { Console.WriteLine("服务已开启,正在通过地址{0}进行监听", host.BaseAddresses[0].ToString()); }; host.Open(); } Console.Read(); } } }
浏览器访问的url是这样的
http://localhost:9001/Calculator
做最好的自己
答案
-
哈,这样啊,我还没这么写过。
不过看代码,感觉应该把 Console.Read();放到using里,紧跟host.open()后。放在外面的话,host都已经关闭了。
您再试试。- 已标记为答案 NineTyNine_LiPei 2009年10月12日 0:19
-
哈,这样啊,我还没这么写过。
不过看代码,感觉应该把 Console.Read();放到using里,紧跟host.open()后。放在外面的话,host都已经关闭了。
您再试试。
1.有道理。呵呵,实例销毁了。
2.如果还不能解决问题,我建议是代码里添加对<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />的配置。就是增加一个服务元数据终结点。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum- 已标记为答案 NineTyNine_LiPei 2009年10月12日 0:19
全部回复
-
您好,可以配置支持。从webcast截的一段配置,参考试试,注意加粗部分:
<services>
<service name="GigManager.GigManagerService" behaviorConfiguration="serviceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000"/>
<add baseAddress="net.tcp://localhost:9000"/>
</baseAddresses>
</host>
<endpoint address="GigManagerService" contract="GigManager.IGigManagerService" binding="netTcpBinding" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors> -
哈,这样啊,我还没这么写过。
不过看代码,感觉应该把 Console.Read();放到using里,紧跟host.open()后。放在外面的话,host都已经关闭了。
您再试试。- 已标记为答案 NineTyNine_LiPei 2009年10月12日 0:19
-
哈,这样啊,我还没这么写过。
不过看代码,感觉应该把 Console.Read();放到using里,紧跟host.open()后。放在外面的话,host都已经关闭了。
您再试试。
1.有道理。呵呵,实例销毁了。
2.如果还不能解决问题,我建议是代码里添加对<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />的配置。就是增加一个服务元数据终结点。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum- 已标记为答案 NineTyNine_LiPei 2009年10月12日 0:19