gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:39:17 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com