我正在尝试在我们的解决方案中的现有Web服务上启用SSL / HTTPS。我在IIS7中的应用程序上选择了Require SSL,并为整个网站(localhost,端口443,*)设置了https绑定,并附加了有效的测试证书。我还将这些设置复制到我们的实时服务器以进行进一步测试,但使用的是合法证书。我可以在两台服务器上通过HTTPS查看正常的.aspx页面。
问题出现在我访问https://servername/basewebservices/message.svc/GetBasket而不是接收通常的json响应时,我得到http我得到404.0错误。我似乎无法解决这个问题。我在web.config中尝试了各种设置,没有任何乐趣。
我试图建立一个全新的网络服务,但仍然无法让https工作。无论是让我当前的服务工作还是指向如何设置(理想情况下不是MVC)安全Web服务的万无一失的演练,都将是惊人的。
我在BaseWebServices中有一个default.aspx,显示在http和https上。我注意到https://localhost/basewebservices/Message.svc显示了默认的邮件服务页面。将/ GetBasket添加到url会向我显示404错误。
我将从我们的解决方案中包含BaseWebServices项目的代码:
IMessage.cs
using System;
using System.Configuration;
using System.Collections.Generic;
using System.ServiceModel.Activation;
using System.Text;
namespace BaseWebServices
{
// NOTE: If you change the class name "Message" here, you must also update the reference to "Message" in Web.config and in the associated .svc file.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Message : IMessage
{
private string DBConn { get; set; }
public Message()
{
DBConn = ConfigurationManager.AppSettings["DBConn"];
}
public List<BasketItemDTO> GetBasket()
{
try
{
var customerController = new BaseWeb.BaseCustomer.CustomerController(DBConn);
int customerId = customerController.GetCustomerIdFromCookie();
if (customerId != 0)
{
var shoppingCartController = new ShoppingCartController(DBConn);
var result = shoppingCartController.GetShoppingCart((int)customerId);
return result;
}
else
return new List<BasketItemDTO>();
}
catch
{
throw;
}
}
}
Message.svc
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.6.2"/>
<authentication mode="Forms"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
<services>
<service behaviorConfiguration="BaseWebServices.MessageBehavior"
name="BaseWebServices.Message">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding"
name="webEndPoint" contract="BaseWebServices.IMessage" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="BaseWebServices.MessageBehavior"
name="BaseWebServices.Service">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding"
bindingConfiguration="httpBinding" name="webEndPoint" contract="BaseWebServices.IService" />
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding"
bindingConfiguration="httpsBinding" name="httpsEndPoint" contract="BaseWebServices.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="httpBinding" allowCookies="false">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</binding>
<binding name="httpsBinding" allowCookies="false">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
<behavior name="wsHttpBinding" />
<behavior name="BaseWebServices.TestSVCAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="BaseWebServices.MessageBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
的web.config
state=([^\n]+)\&
code=([^\n]+)
任何帮助或指出我忽略的明显事实都会非常感激。我昨天花了一整天时间尝试各种配置来实现这个目的。这是我的第一个SO帖子,所以如果我做了一些愚蠢的指出,我会说得对。