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/