公共反向代理背后的WCF Web服务

Rob*_*cea 8 wcf wsdl reverse-proxy

如何从侦听公共IP的反向代理后面正确地为位于私有LAN中的WCF Web服务提供WSDL?

我有一个以反向代理模式配置的Apache Web服务器,它侦听公共IP地址上的请求,并从内部IIS主机提供服务.WCF webservice使用LAN主机的FQDN地址生成WSDL,当然,互联网Web服务客户端无法读取该地址.

是否有任何设置可以在wcf应用程序的web.config或IIS中配置,以自定义生成的包含主机地址的WSDL并放置公共地址?

Ric*_*tte 9

对您的服务类添加属性:

<ServiceBehavior(AddressFilterMode:=AddressFilterMode.Any)>
Run Code Online (Sandbox Code Playgroud)

这允许客户端将服务作为https:// ...来解决,但是要在http://上托管服务.请参阅此答案,了解如何创建扩展以允许AddressFilterMode.Any为通过配置指定,无需代码属性.

在服务主机的web.config中,端点元素必须在address属性中具有绝对URL,该URL是客户端将使用的公共URL.在同一个端点元素中,将listenUri属性设置为服务主机正在侦听的绝对URL.我确定主机正在侦听的默认绝对URI的方式是在客户端应用程序中添加服务引用,该服务引用指向托管服务的物理服务器.客户端的web.config将具有该服务的地址.然后我将其复制到主机web.config中的listenUri属性中.

在服务行为配置中,添加具有属性httpGetEnabled = true的元素serviceMetaData

所以你会有类似的东西:

<serviceBehaviors>
  <behavior name="myBehavior">
    <serviceMetadata httpGetEnabled="true" />
  </behavior
</serviceBehaviors>
...
<services>
  <service name="NamespaceQualifiedServiceClass" behavior="myBehavior" >
    <endpoint address="https://www.sslloadbalancer.com" binding="someBinding" contract="IMyServiceInterface" listenUri="http://www.servicehost.com" ...  />
  </service>
</services>
Run Code Online (Sandbox Code Playgroud)

我不确定这是否适用于邮件安全性或传输安全性.对于此特定应用程序,凭据作为DataContract的一部分传递,因此我们有basicHttpBinding安全模式= none.由于传输是安全的(对于ssl负载平衡器),因此没有安全问题.

也可以将listenUri属性留空,但必须存在.

遗憾的是,WCF中存在一个错误,其中WSDL中导入的模式的基地址具有listenUri基地址而不是公共基地址(使用端点的地址属性配置的地址).要解决该问题,您需要创建一个IWsdlExportExtension实现,它将导入的模式直接引入WSDL文档并删除导入.这方面的一个例子是http://winterdom.com/2006/10/inlinexsdinwsdlwithwcf.此外,您可以让示例类继承BehaviorExtensionElement并使用以下方法完成两个新方法:

Public Overrides ReadOnly Property BehaviorType() As System.Type
    Get
        Return GetType(InlineXsdInWsdlBehavior)
    End Get
End Property

Protected Overrides Function CreateBehavior() As Object
    Return New InlineXsdInWsdlBehavior()
End Function
Run Code Online (Sandbox Code Playgroud)

这将允许您在.config文件中添加扩展行为,并使用配置添加行为,而不必创建服务工厂.

在system.servicemodel配置元素下添加:

  <endpointBehaviors>
    <behavior name="SSLLoadBalancerBehavior">          
      <flattenXsdImports/>
    </behavior>
  </endpointBehaviors>
        </behaviors>
<extensions>
  <behaviorExtensions>
    <!--The full assembly name must be specified in the type attribute as of WCF 3.5sp1-->
    <add name="flattenXsdImports" type="Org.ServiceModel.Description.FlattenXsdImportsEndpointBehavior, Org.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>        
  </behaviorExtensions>
</extensions>
Run Code Online (Sandbox Code Playgroud)

然后使用behaviorConfiguration属性引用端点配置中的新端点行为

<endpoint address="" binding="basicHttpBinding" contract="WCFWsdlFlatten.IService1" behaviorConfiguration="SSLLoadBalancerBehavior">
Run Code Online (Sandbox Code Playgroud)


Nic*_*ier 0

请参阅:Aaron Skonnard 的服务站 WCF 深入寻址

存档链接

  • 该内容似乎已移至 http://msdn.microsoft.com/en-us/magazine/cc163412.aspx 。 (3认同)