【问题标题】:Expose WCF Web service on the internet configuration在 Internet 配置上公开 WCF Web 服务
【发布时间】:2012-01-30 08:04:33
【问题描述】:

我正在尝试将用 WCF 编写的 web 服务公开给开放的互联网,但我无法将其配置为从外部 url 使用。

网络服务在https://ourportal.internaldomain.intra:9011/FrontEndWS 内部托管并且运行良好。我们已经在https://www.internetdomain.com.mt/FrontEndWS 上公开了 web 服务,但是当从外部地址访问它时,soap URL 仍然指向内部地址。

我们的设置如下。我们不需要在内部公开 web 服务,只需要在互联网上公开,这样可以简化配置。

<bindings>
 <basicHttpBinding>
   <binding name="LargeMessagingBinding" maxBufferSize="99999900" maxBufferPoolSize="524288000" maxReceivedMessageSize="99999900">
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="99999900" maxBytesPerRead="99999900" maxNameTableCharCount="2147483647" />
     <security>
       <transport clientCredentialType="Basic" />
     </security>
   </binding>
 </basicHttpBinding>
</bindings>
<behaviors>
 <serviceBehaviors>
   <behavior name="ServiceBehaviour">
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"  />
     <serviceDebug includeExceptionDetailInFaults="true" />
     <dataContractSerializer maxItemsInObjectGraph="6553600" />
   </behavior>
 </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="false" />

【问题讨论】:

  • 您的机器上有多个网卡吗?您是否尝试为您的服务指定基地址?
  • 您的配置中没有 &lt;services&gt; 标记 - 您没有定义任何服务.....
  • @hasam khan - 两个问题都否。
  • @marc_s - 我是否将外部 URL 放在服务标签中?
  • 嗯 - 是的 - 您需要定义如何使用 (A) 地址、(B) 索引、(C) 合同从外部世界访问您的服务WCF....

标签: asp.net wcf web-services wcf-binding


【解决方案1】:

为了将您的 Web 服务公开给外部世界,您需要将 WCF 服务放在 IIS 网站下的虚拟目录中。

现在您的网址“www.internetdomain.com.nt”将映射到特定的 IP 地址(外部可访问),该 IP 地址是您的 WCF 服务公开的服务器的 IP 地址。

IIS 接收此 IP 上的任何请求,并确定如何处理该请求。

如果上述情况正常,那么您的 WCF 服务的 URL 将是:

http://www.internetdomain.com.nt/virtualdirectory/FrontEndWS
https://www.internetdomain.com.nt/virtualdirectory/FrontEndWS

对于 https 情况,您的网站将通过 Edit Bindings 选项映射 443 https 端口,并指定它需要使用的服务证书。

您还需要在 web.config 中使用端点定义您的服务。示例如下:

<bindings>
 <basicHttpBinding>
   <binding name="LargeMessagingBinding" maxBufferSize="99999900" maxBufferPoolSize="524288000" maxReceivedMessageSize="99999900">
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="99999900" maxBytesPerRead="99999900" maxNameTableCharCount="2147483647" />
     <security>
       <transport clientCredentialType="Basic" />
     </security>
   </binding>
 </basicHttpBinding>
</bindings>
<services>
      <service name="SampleWCFService.Service1" behaviorConfiguration="default">
        <endpoint address="" behaviorConfiguration="ServiceBehaviour" binding="basicHttpBinding" bindingConfiguration="LargeMessageBinding" contract="SampleWCFService.IService1"/>
      </service>
</services>
<behaviors>
 <serviceBehaviors>
   <behavior name="ServiceBehaviour">
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"  />
     <serviceDebug includeExceptionDetailInFaults="true" />
     <dataContractSerializer maxItemsInObjectGraph="6553600" />
   </behavior>
 </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="false" />

检查上述配置中的 services 元素。确保正确指定服务的命名空间。

【讨论】:

  • Web 服务将可通过 https 上的 SSL 访问。可以使用basicHttpBinding吗?
  • 如果您尝试使用 basicHttpBinding 然后使用用户名身份验证,它将无法工作,因为 WCF 不允许用户名在通道上以明文形式传递。
  • 但是我已经尝试过了,它奏效了。为了确保我没有问题你会在这里建议什么绑定?
  • 是的,通过 SSL 进行用户名身份验证的 BasicHttpBinding 有效。如果您没有 SSL,则不会。在某些情况下,SSL 在负载均衡器处终止,然后流量被定向到网站,在这种情况下,您无法使用带有用户名身份验证的 basicHttpBinding。绑定类型取决于您的要求。为了让服务遵守基本配置文件 1.1 basicHttpBinding 应该足够了
  • 谢谢。我尝试定义端点地址,但出现以下错误:没有协议绑定与给定地址“domain.com.mt/FrontEndWS”匹配。协议绑定在 IIS 或 WAS 配置中的站点级别进行配置。
【解决方案2】:

我遇到了同样的问题,现在发现这是因为位于 Web 服务器前面的 SSL 卸载程序。请与您的管理员组联系。我们摆脱了 SSL 卸载程序,因为我们必须建立服务。 您可以参考以下链接

http://blogs.msdn.com/b/distributedservices/archive/2010/06/01/ssl-offloader-using-wcf-4-0-routing-service.aspx

http://blogs.msdn.com/b/distributedservices/archive/2010/05/13/wcf-and-intermediate-devices.aspx

还为 https 添加主机头

http://www.sslshopper.com/article-ssl-host-headers-in-iis-7.html

【讨论】:

    猜你喜欢
    • 2012-08-29
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 2015-11-18
    • 1970-01-01
    相关资源
    最近更新 更多