【问题标题】:Web SVC works on HTTP but not HTTPSWeb SVC 适用于 HTTP 但不适用于 HTTPS
【发布时间】:2015-01-05 15:18:22
【问题描述】:

我尝试了几种在网上发布的解决方案,但似乎都没有效果。

我对网络服务方法的响应是:

404:找不到文件或目录。

当我访问 AddressService.svc 文件的 http 版本时,我得到一个服务描述。当我访问该方法 (AddressService.svc/ValidateAddress) 时,我得到“不允许使用 GET 方法”,这是预期的,因为它只是一个 POST 方法。当我尝试 AddressService.svc 页面的 https 版本时,我还获得了服务描述。但是,当我尝试访问方法 (AddressService.svc/ValidateAddress) 时,我得到 404/not found 结果。

这是我目前在 web.config 中的内容:

绑定:

<bindings>
  <basicHttpBinding>
    <binding name="WebServiceSoap">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>

服务:

  <service name="DefiningVoiceWeb.AddressService" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="DefiningVoiceWeb.IAddressService" behaviorConfiguration="web" />
    <host>
      <baseAddresses>
        <add baseAddress="https://www.definingvoice.com/AdminOnly/AddressService.svc" />
      </baseAddresses>
    </host>
  </service>

服务行为:

  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>

我还为 CORS 添加了这个:

<httpProtocol>
    <customHeaders>
        <clear />
        <add name="X-Powered-By" value="ASP.NET" />
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="GET, POST" />
    </customHeaders>
</httpProtocol>

这是我的 IAddressService 声明:

[ServiceContract]
public interface IAddressService
{
    [OperationContract]
    [WebInvoke(Method = "POST",
        UriTemplate = "/ValidateAddress",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json)]
    Address ValidateAddress(Address address);
}

还有AddressService.svc:

<%@ ServiceHost Language="C#" Debug="true" Service="DefiningVoiceWeb.AddressService" CodeBehind="AddressService.svc.cs" %>

我已经尝试了这些页面中的解决方案,但它们似乎都不适合我:

如果我可能做错了什么,我很乐意尝试上述解决方案之一。如果我需要提供更多详细信息,请告诉我。

提前致谢。


阅读@pepo 提供的链接后,我发现了问题。以下是我使用最终工作配置编辑的部分:

服务:

  <service name="DefiningVoiceWeb.AddressService" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" contract="DefiningVoiceWeb.IAddressService" behaviorConfiguration="webHttpBehavior" />
    <host>
      <baseAddresses>
        <add baseAddress="https://www.definingvoice.com/AdminOnly/" />
      </baseAddresses>
    </host>
  </service>

绑定:

<bindings>
  <webHttpBinding>
    <binding name="webHttpTransportSecurity">
      <security mode="Transport">
      </security>
    </binding>
  </webHttpBinding>
</bindings>

【问题讨论】:

  • 您查看过事件日志吗?当您从 localhost 访问服务元数据时会发生什么?应该有更多关于激活服务缺少什么的信息。
  • 不幸的是,我无法访问我托管该网站的事件日志。我将尝试在本地主机上的 IIS Express 中的 https 下运行该站点。我没想过要试试。我现在就试试……
  • 好的,我取得了一些进展。在 localhost 上运行后,我发现 web.config 存在一些问题。我从 http 配置恢复到工作配置,然后添加了一些装饰,例如 mode="Transport" 和上面示例中的其他装饰。现在,当我转到与 http 版本类似的 https//...AddressService.svc 时,我得到了该服务的描述,但是当我尝试访问 AddressService.svc/ValidateAddress 方法时,响应不同(请参阅上面的更新)。有什么想法吗?

标签: web-services wcf https


【解决方案1】:

那么,为什么你在使用weHttpBinding的时候还要编辑basicHttp绑定配置呢?

This SO answer 可能会帮助你(虽然我没有测试过)。参考了一篇很好的文章,解释了如何使用 webHttpBinding 设置 https。

【讨论】:

  • 那是一篇好文章。感谢您的链接。今晚我会通读一遍,并尝试将我的解决方案与他的示例相匹配。
  • 终于!至少我认为,问题在于我使用的是 basicHttpBinding 而不是 webHttpBinding,并且我没有将 bindingConfiguration 添加到服务中。我会发布我的修改。再次感谢您的链接。这是一篇好文章。
猜你喜欢
  • 2014-08-15
  • 1970-01-01
  • 2019-02-28
  • 2018-07-20
  • 2013-11-30
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多