如何通过 PowerShell 通过 LTM 代理访问 WCF SOAP 服务?

How do I access a WCF SOAP service through an LTM proxy via PowerShell?

我正在使用 PowerShell 访问 WCF SOAP 服务。这是直接在 WCF 终结点主机上进行的所有操作。我正在使用:

$request = New-WebServiceProxy -uri ${using:endpoint}"?wsdl" -class "MyService" -namespace "MS"

我有一台位于 F5 本地流量管理器 (LTM) 后面的新服务器。当我尝试同样的事情时,我收到错误,因为返回的 WSDL 包含指向服务器本身的链接,这是不可访问的,而不是指向 LTM 端点的链接。

这导致:

The document was understood, but it could not be processed.
  - The WSDL document contains links that could not be resolved.
  - There was an error downloading 'http://myhost/MyService/MyService.svc?xsd=xsd0'.
  - Unable to connect to the remote server
  - No connection could be made because the target machine actively refused it 192.168.1.1:80
    + CategoryInfo          : InvalidOperation: (http://192.168.1...ervice.svc?wsdl:Uri) [New-WebServiceProxy], Invalid
   OperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.NewWebServiceProxy
    + PSComputerName        : localhost

我需要什么才能让 LTM host/IP 出现在 WSDL 中?服务 web.config 中是否有我遗漏的某些设置?

将以下内容添加到您的 web.config 文件中:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <useRequestHeadersForMetadataAddress />

如果没有上述内容,WCF 将从 IIS 获取 url 以呈现。您还可以将主机 headers 添加到托管 WCF 的 site/application 的绑定中,它将使用它。