C# 仅代码WCF主机具有;“本地主机”;在指向wsdl的链接中

C# 仅代码WCF主机具有;“本地主机”;在指向wsdl的链接中,c#,visual-studio,wcf,wsdl,service-reference,C#,Visual Studio,Wcf,Wsdl,Service Reference,我有一个wcf服务,我在一个控制台应用程序中自我托管 当我运行服务并将其部署到一台机器(称之为MyWCFRunningMachine)时,我可以转到“youhavecreateaservice”页面。(http://MyWCFRunningMachine:8090/MyService) 但是它提供了一个指向wsdl页面的链接。该链接如下所示:http://localhost:8090/MyService?wsdl 因此,当我单击该链接时,它会尝试使用我的机器而不是MyWCFRunningMach

我有一个wcf服务,我在一个控制台应用程序中自我托管

当我运行服务并将其部署到一台机器(称之为MyWCFRunningMachine)时,我可以转到“youhavecreateaservice”页面。(http://MyWCFRunningMachine:8090/MyService)

但是它提供了一个指向wsdl页面的链接。该链接如下所示:http://localhost:8090/MyService?wsdl

因此,当我单击该链接时,它会尝试使用我的机器而不是MyWCFRunningMachine连接到该服务

如果我冷输入到wsdl的路径(http://MyWCFRunningMachine:8090/MyService?wsdl)然后我在浏览器中看到一个wsdl。但如果尝试添加服务引用,则会出现以下错误:

该文档已被理解,但无法处理。
-WSDL文档包含无法解析的链接。
-下载“http://localhost:8090/MyService?xsd=xsd0”时出错

这也引用了localhost,但不应该引用

以下是我用于自托管服务的代码:

public class SelfServiceHost
{
    static string StartUpUrl {get{return "http://localhost:8090/MyService";}}
    static void Main(string[] args) { StartupService(StartUpUrl); }

    public static ServiceHost StartupService(string startUpUrl)
    {
        //+ Setup the Service
        //Create a URI to serve as the base address
        Uri httpUrl = new Uri(startUpUrl);
        //Create ServiceHost
        ServiceHost host = new ServiceHost(typeof(MyService), httpUrl);
        //Add a service endpoint
        host.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), "");
        //Enable metadata exchange
        ServiceMetadataBehavior serviceMetadataBehavior =  
             new ServiceMetadataBehavior {HttpGetEnabled = true};
        host.Description.Behaviors.Add(serviceMetadataBehavior);

        //! Turn on Debug.  Remove for production!
        host.Description.Behaviors.Remove(typeof (ServiceDebugBehavior));
        ServiceDebugBehavior serviceDebugBehavior = 
            new ServiceDebugBehavior {IncludeExceptionDetailInFaults = true};
        host.Description.Behaviors.Add(serviceDebugBehavior);

        //Start the Service
        host.Open();
        Console.WriteLine("Service is hosted at " + httpUrl);
        Console.ReadLine();

        return host;
    }
}
我怎样才能让它删除本地主机?(注意:我无法将其硬编码到MyWCFRunningMachine。此服务将在多台不同的机器上运行


我是否需要使用在移动机器时更改的配置文件?(我不使用配置文件,因为我不想为我的控制台应用程序设置配置文件,但如果这是唯一的方法,那么我会这样做。)

我认为您使用配置文件保存机器名是正确的

“http://“+MACHINE_NAME+”:8090/MyService”


安装服务后,在配置文件中更改该值,然后重新启动服务以将其引入。

我认为您使用配置文件保存机器名是正确的

“http://“+MACHINE_NAME+”:8090/MyService”

安装服务后,在配置文件中更改该值,然后重新启动服务以将其引入