c# - WCF 服务自主机 url 未获取 wsdl 文档

标签 c# .net wcf self-hosting

namespace helloserviceSelfHostingDemo
{
    [ServiceContract]
    interface IhelloService
    {
        [OperationContract]
        string sayhello(string name);
    }

public class HelloService : IhelloService
{

    public string sayhello(string name)
    {
        return "hello " + name;
    }
}
class Program
{
    static void Main(string[] args)
    {
        ServiceHost host = new ServiceHost(typeof(HelloService));
        BasicHttpBinding bind = new BasicHttpBinding();
        host.AddServiceEndpoint(typeof(IhelloService), bind, "http://8080/myhelloservice");
        host.Open();
        Console.WriteLine("hello service is running");
        Console.ReadKey();
    }
}

此代码运行良好,但当我在浏览器中复制此地址时,无法获得服务

最佳答案

您需要像这样的 mex 绑定(bind):

string mexAddress = "http://localhost:8000/servicemodelsamples/service/mex";
MetadataExchangeClient mexClient = new MetadataExchangeClient("MyMexEndpoint");
mexClient.ResolveMetadataReferences = true;
MetadataSet mdSet = mexClient.GetMetadata(new EndpointAddress(mexAddress));

如果没有 Mex,当导航到 URL 时就没有要发布的元数据。

关于c# - WCF 服务自主机 url 未获取 wsdl 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24008470/

相关文章:

c# - 在datagridview中搜索数据

c# - 在 Multi-Tenancy 应用程序中使用 IOptions 和从数据库加载选项

wcf - 使用 WCF HTTPS 终结点从控制台应用程序调用 Service Fabric 服务

wcf - 使用 makecert.exe 创建的证书在哪里?

c# - 此特定场景中的最佳缓存策略

c# - Windows Phone 8 设备可以用于测试使用 WP SDK 7.1 构建的应用程序吗

c# - 如何隐藏类背后的逻辑以提高方法的可读性和重构类以遵循 SRP?

c# - SqlCommand.ExecuteReader 是否会自动打开数据库连接?

c# - TCP Socket.Connect 正在生成误报

c# - 为自定义类型设置 DataView(或 DataTable.DefaultView)RowFilter