【问题标题】:WCF not using computer name instead of domain name when viewing MyService.svc?wsdl查看 MyService.svc?wsdl 时 WCF 不使用计算机名而不是域名
【发布时间】:2010-10-02 23:26:14
【问题描述】:

我的 WCF 服务似乎使用的是计算机名而不是域名。当我查看MyService.svc?wsdl 链接时,它显示的是我的计算机名称。

在 web.config 中的何处添加我的域名?端点地址、基地址或身份?

注意:我使用的是 SSL,所以它必须是 https://www.example.com/myservice.svc

【问题讨论】:

  • 看看这个post能不能帮上忙。
  • 真是个小技巧。这是一个已知的错误吗,因为我看不到共享主机如何处理这个问题!

标签: web-services wcf iis ssl configuration


【解决方案1】:

WCF 4.0 在某些情况下通过使用请求标头的新配置选项解决了这个问题:

    <behaviors>
        <serviceBehaviors>
            <behavior name="AutoVaultUploadBehavior">
                <useRequestHeadersForMetadataAddress>
                    <defaultPorts>
                        <add scheme="https" port="443" />
                    </defaultPorts>
                </useRequestHeadersForMetadataAddress>

【讨论】:

  • 同样的问题,这个解决方案非常适合我。谢谢!
  • 对于 http?怎么办?
【解决方案2】:

对于 IIS7,您不需要将其添加到 web.config,而是添加到 IIS 配置文件中。

首先编辑您网站的绑定,以便 HTTP 协议指定一个主机名(如果您还没有) - 这将确保它在 HTTP 下获得正确的名称。

导航到 C:\Windows\System32\inetsrv\config 并打开 applicationHost.config

查找网站部分。你会看到类似下面的内容

<sites>
  <site name="Default Web Site" id="1">
    <application path="/">
        <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:80:puck" />
      <binding protocol="net.tcp" bindingInformation="808:*" />
      <binding protocol="net.pipe" bindingInformation="*" />
      <binding protocol="net.msmq" bindingInformation="localhost" />
      <binding protocol="msmq.formatname" bindingInformation="localhost" />
      <binding protocol="http" bindingInformation="*:80:puck.idunno.org" />
      <binding protocol="http" bindingInformation="*:80:localhost" />
      <binding protocol="https" bindingInformation="*:443:" />
    </bindings>
  </site>
  ....
</sites>

您可以看到 http 协议的绑定指定了主机标头,但 https 没有。当您浏览网页时,您不能通过 HTTPS 使用主机标头,但 WCF 在生成 WSDL 时仍会使用它 - 如果找不到,它将回退到机器名称。

所以你需要做的就是像这样编辑 HTTPS 绑定

      <binding protocol="https" bindingInformation="*:443:puck" />

将正确的 FQDN 附加到绑定信息的末尾。重置 IIS 和 WCF 应该现在就可以了。

IIS6 的解决方案已经被darin 贴出来了

【讨论】:

  • 这行得通,但我遇到了一个问题,只有我指定的确切域名才能工作。例如,如果我这样做: *:443:domain.com 那么只有 domain.com/Service.svc 会起作用,如果我这样做: *:443:www.domain.com 那么只有 www.domain.com/Service.svc 会工作,但不是两者兼而有之。我怎样才能得到两者? (带 https 前缀)
【解决方案3】:

如此链接中所述WCF is using the computer name instead of the IP address and cannot be resolved

它解决了我的问题,可能是因为我在同一个主机上有多个网站,而且非常简单。

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

【讨论】:

    【解决方案4】:

    解决此问题 在 web.config 文件中配置 httpGetEnabled 属性和 httpsGetEnabled 属性

    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
    

    【讨论】:

    • 简单,容易,正是需要的。不知道为什么其他人都建议所有其他复杂的解决方案。这正是 OP 想要的。
    • 这对我来说很重要!谢谢@Haridharan
    【解决方案5】:

    我们正在使用WCFExtras 更改主机名。

    WCFExtras 是一个小型开源库,可让您编写以下代码来更改主机名:

    <behaviors>
      <endpointBehaviors>
        <behavior name="xxx">
          <wsdlExtensions location="http://some-hostname-visible-from-outside/path-to-a-service/service.svc" singleFile="True" />
        </behavior>
      ...
    

    【讨论】:

      【解决方案6】:

      只是添加 &lt;useRequestHeadersForMetadataAddress&gt;&lt;/useRequestHeadersForMetadataAddress&gt; 解决了我的问题。 似乎 WCF 4.0 通过添加这个来处理标题 我使用 SSL 访问 WCF 服务。

      【讨论】:

        【解决方案7】:

        我在这里添加了解决方案,http://knowledgebaseworld.blogspot.com/2010/06/domain-name-replaced-with-machine-name.html。它应该对你们所有人都有效,因为它在本地、暂存和生产方面与我一起工作正常,而无需对 iis 进行绑定

        【讨论】:

          【解决方案8】:

          这些解决方案都对我没有帮助。我能够通过一个非常简单的自定义服务工厂来解决这个问题。

          Installing a WCF Service on a Shared Hosting Site, Revisited

          【讨论】:

            【解决方案9】:

            【讨论】:

              【解决方案10】:

              虽然它是一个旧帖子,但这里有一个答案。 在 Service Behavior --> ServiceMetaData 添加服务 url。

              请注意,如果不添加myService,会抛出另一个错误。

              【讨论】:

                【解决方案11】:

                我的生产服务器遇到了这个问题。我找到了有关 IIS 和 WCF 问题的多个主机标头的各种文章,但是如果您使用 SSL,则无法将主机标头添加到 IIS UI 中的网站身份,您只能将它们添加到正常的 HTTP 身份:

                但是,您可以通过命令提示符脚本添加 SSL 主机标头,这为我解决了这个问题:

                cscript.exe adsutil.vbs set /w3svc/<site identifier>/SecureBindings ":443:<host header>"
                

                有关此内容的更多信息,请参阅此链接:http://blumenthalit.net/blog/Lists/Posts/Post.aspx?ID=14

                【讨论】:

                  【解决方案12】:

                  这篇文章为我解决了这个问题。我需要在 IIS 中将我的域名与我的 IP 地址和网站相关联。

                  http://www.codemeit.com/wcf/wcf-wsdl-xsdimport-schemalocations-link-to-local-machine-name-not-domain-name-while-hosted-in-iis.html

                  【讨论】:

                    【解决方案13】:

                    感谢卡纳斯·罗伯特。 解决我的问题的步骤 - 1.在浏览器中生成wsdl并保存到文件(通过从浏览器中点击.svc?wsdl)另存为.wsdl

                    1. 通过从 wsdl(xsd=xsd0 等)点击 url 生成 xsd 文件,并从浏览器保存到文件,另存为 .wsdl

                    2. 用域名(或 ip 地址)替换来自 wsdl 的所有机器名引用,并更改 xsd 引用并保存并用域名(或 ip 地址)替换来自 xsd 文件的所有机器名引用 确保使用 .xsd 扩展名命名 xsd 文件(即,name0.xsd、name1.xsd、name2.xsd)

                    3. 将 wsdl 和 xsd 文件复制到虚拟目录 在您的 web.config 中添加以下行:

                    <behaviors>
                          <serviceBehaviors>
                            <behavior name="MyServiceBehavior">
                              <serviceMetadata httpGetEnabled="true" externalMetadataLocation="http://IPorDomainName/MyServices/FileTransferService.wsdl"  />
                              <serviceDebug includeExceptionDetailInFaults="false" />
                            </behavior>
                          </serviceBehaviors>
                        </behaviors>

                    【讨论】:

                      猜你喜欢
                      • 2011-10-15
                      • 1970-01-01
                      • 1970-01-01
                      • 2011-10-09
                      • 1970-01-01
                      • 2022-12-09
                      • 1970-01-01
                      • 2020-03-18
                      • 2013-01-13
                      相关资源
                      最近更新 更多