【问题标题】:How can I force the .NET ASMX WSDL generation to change a soap:address location from http to https?如何强制.NET ASMX WSDL 生成将soap:address 位置从http 更改为https?
【发布时间】:2022-11-05 04:55:37
【问题描述】:

使用托管在 SSL 卸载后面的 VB.NET asmx 项目,我需要更改生成的 WSDL 以显示肥皂的 https:地址。

from: <soap:address location="http://example.com/example.asmx"/>
to: <soap:address location="https://example.com/example.asmx"/>

最好在代码之外,这样我们就可以影响构建过程。

【问题讨论】:

    标签: wsdl asmx


    【解决方案1】:

    这取决于您使用的是什么系统用于生成wsdl。 您分享说您正在使用 VB.NET,但它并没有缩小到足以 100% 回答您的问题。如果您可以显示一些代码,那么我们可以提供帮助。另外据我所知,WSDL 文件中的位置与客户端访问它的位置相同(它到达的URL)。这意味着当卸载发生在其他地方时,location 可能总是http

    如果没有更多信息,我会为您看到三个选项:

    1. 配置 TLS 卸载程序以将查询从 http 重定向到 httpS。 (从安全的角度来看,这也是推荐的设置。)
    2. 在卸载发生的地方使用解决方案来替换响应的内容。 (这具有特定于环境的优势。)
    3. 在内部应用程序上也使用自签名证书,因此地址将正确生成。 (这可能有点难以破解,但它的好处是不依赖于其他配置,并且必须为从开发到上线的每个环境修改该配置。)

      C#它可以在代码https://learn.microsoft.com/en-us/archive/blogs/kaevans/modify-a-web-services-wsdl-using-a-soapextensionreflector 中完成,并且相当复杂。如果你有一台开发机器,那么你也需要使用 TLS ......但是你去:

      using System;
      using System.Web.Services.Description;
      
      namespace Msdn.Web.Services.Samples
      {
          public class HttpsReflector : SoapExtensionReflector
          {
              public override void ReflectMethod()
              {
                  //no-op
              }
      
              public override void ReflectDescription()
              {
                  ServiceDescription description = ReflectionContext.ServiceDescription;
                  foreach (Service service in description.Services)
                  {
                      foreach (Port port in service.Ports)
                      {
                          foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                          {
                              SoapAddressBinding binding = extension as SoapAddressBinding;
                              if (null != binding)
                              {
                                  binding.Location = binding.Location.Replace("https://", "https://");
                              }
                          }
                      }
                  }
              }
          }
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2011-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      相关资源
      最近更新 更多