use*_*649 6 .net c# 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();
}
}
Run Code Online (Sandbox Code Playgroud)
}
这段代码运行良好但是当我复制时,浏览器中的这个地址没有得到服务
您需要您的 mex 绑定,如下所示:
string mexAddress = "http://localhost:8000/servicemodelsamples/service/mex";
MetadataExchangeClient mexClient = new MetadataExchangeClient("MyMexEndpoint");
mexClient.ResolveMetadataReferences = true;
MetadataSet mdSet = mexClient.GetMetadata(new EndpointAddress(mexAddress));
Run Code Online (Sandbox Code Playgroud)
如果没有 Mex,当用户导航到 URL 时就没有可发布的元数据。