C# 在浏览器中键入url时,自托管WCF服务不工作?

C# 在浏览器中键入url时,自托管WCF服务不工作?,c#,.net,wcf,C#,.net,Wcf,我是wcf的新手。我制作了简单的自托管服务并添加了app.config,但当我在浏览器中键入地址时,它不会显示我们创建服务时获得的服务页面http://localhost:8067/WCFService它没有显示我们运行服务时显示的服务。但是,当我尝试在publicstaticvoidmain而不是app.config中添加基本服务时,它工作正常,我没有得到??有人能帮我吗 以下是手动添加的app.config文件: <configuration> <system.se

我是wcf的新手。我制作了简单的自托管服务并添加了
app.config
,但当我在浏览器中键入地址时,它不会显示我们创建服务时获得的服务页面
http://localhost:8067/WCFService
它没有显示我们运行服务时显示的服务。但是,当我尝试在
publicstaticvoidmain
而不是
app.config
中添加基本服务时,它工作正常,我没有得到??有人能帮我吗

以下是手动添加的
app.config
文件:

<configuration>
    <system.serviceModel>
        <services>
            <service name="SelfHostedWCFService.WCFService">
                <endpoint 
                 address="http://localhost:8067/WCFService" 
                 binding="wsHttpBinding" 
                 contract="SelfHostedWCFService.IWCFService">
                </endpoint>
            </service>
        </services>
    </system.serviceModel>
</configuration>
namespace SelfHostedWCFService
{    
    [ServiceContract]
    interface IWCFService
    {
        [OperationContract]
        int Add(int a,int b);

        [OperationContract]
        int Sub(int a,int b);

        [OperationContract]
        int Mul(int a, int b);
    }
}
namespace SelfHostedWCFService
{
    class WCFService : IWCFService
    {
        public int Add(int a, int b)
        {
            return (a + b);
        }

        public int Sub(int a, int b)
        {
            return (a-b);
        }

        public int Mul(int a, int b)
        {
            return (a*b);
        }
    }
}
以下是手动添加的接口文件:

<configuration>
    <system.serviceModel>
        <services>
            <service name="SelfHostedWCFService.WCFService">
                <endpoint 
                 address="http://localhost:8067/WCFService" 
                 binding="wsHttpBinding" 
                 contract="SelfHostedWCFService.IWCFService">
                </endpoint>
            </service>
        </services>
    </system.serviceModel>
</configuration>
namespace SelfHostedWCFService
{    
    [ServiceContract]
    interface IWCFService
    {
        [OperationContract]
        int Add(int a,int b);

        [OperationContract]
        int Sub(int a,int b);

        [OperationContract]
        int Mul(int a, int b);
    }
}
namespace SelfHostedWCFService
{
    class WCFService : IWCFService
    {
        public int Add(int a, int b)
        {
            return (a + b);
        }

        public int Sub(int a, int b)
        {
            return (a-b);
        }

        public int Mul(int a, int b)
        {
            return (a*b);
        }
    }
}
以下是手动添加的服务cs文件:

<configuration>
    <system.serviceModel>
        <services>
            <service name="SelfHostedWCFService.WCFService">
                <endpoint 
                 address="http://localhost:8067/WCFService" 
                 binding="wsHttpBinding" 
                 contract="SelfHostedWCFService.IWCFService">
                </endpoint>
            </service>
        </services>
    </system.serviceModel>
</configuration>
namespace SelfHostedWCFService
{    
    [ServiceContract]
    interface IWCFService
    {
        [OperationContract]
        int Add(int a,int b);

        [OperationContract]
        int Sub(int a,int b);

        [OperationContract]
        int Mul(int a, int b);
    }
}
namespace SelfHostedWCFService
{
    class WCFService : IWCFService
    {
        public int Add(int a, int b)
        {
            return (a + b);
        }

        public int Sub(int a, int b)
        {
            return (a-b);
        }

        public int Mul(int a, int b)
        {
            return (a*b);
        }
    }
}

我的
app.config
或其他概念是否有问题???

您还需要将元端点添加到自托管服务中

ServiceMetadataBehavior meta = new ServiceMetadataBehavior();
      meta.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
      _host.Description.Behaviors.Add(meta);

      _host.AddServiceEndpoint(
        ServiceMetadataBehavior.MexContractName,
        MetadataExchangeBindings.CreateMexHttpBinding(),
        "http://localhost:8067/WCFService/mex"
      );

抱歉,有一些输入错误,不是succehttp://localhost:8067/WCFService 忘了浏览器吧。如果您创建一个控制台应用程序并使用“添加服务引用”,它会工作吗?@JohnSaunders的可能副本:没有任何MEX端点,我怀疑添加服务引用会工作-对吗?对。我试图从问题中删除特定于浏览器的行为。例如,浏览器将配置代理,“添加服务引用”将不会。我认为在app.config中这样做更干净,因为其中已经有一个端点。