Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在IIS7上现有的C#.Net 4.6.2 Web服务上启用HTTPS SSL_C#_Ssl_Https_Iis 7_.net 4.6 - Fatal编程技术网

如何在IIS7上现有的C#.Net 4.6.2 Web服务上启用HTTPS SSL

如何在IIS7上现有的C#.Net 4.6.2 Web服务上启用HTTPS SSL,c#,ssl,https,iis-7,.net-4.6,C#,Ssl,Https,Iis 7,.net 4.6,我正在尝试在解决方案中的现有web服务上启用SSL/HTTPS。我在IIS7中选择了需要SSL的应用程序,并为整个网站(localhost,端口443,*)设置了https绑定,并附上了有效的测试证书。我还将这些设置复制到了我们的live服务器上,以便进一步测试,但使用的是合法的证书。我可以在两台服务器上通过HTTPS查看普通的.aspx页面 当我访问时,问题出现了,我没有收到http上通常的json响应,而是收到了404.0错误。我好像绕不开这件事。我在我的web.config中尝试了各种设置

我正在尝试在解决方案中的现有web服务上启用SSL/HTTPS。我在IIS7中选择了需要SSL的应用程序,并为整个网站(localhost,端口443,*)设置了https绑定,并附上了有效的测试证书。我还将这些设置复制到了我们的live服务器上,以便进一步测试,但使用的是合法的证书。我可以在两台服务器上通过HTTPS查看普通的.aspx页面

当我访问时,问题出现了,我没有收到http上通常的json响应,而是收到了404.0错误。我好像绕不开这件事。我在我的web.config中尝试了各种设置,但毫无乐趣

我试图建立一个全新的web服务,但仍然无法使用https。如果能让我当前的服务正常工作,或者能被指向一个简单的、关于如何设置(理想情况下不是MVC)安全web服务的演练,那就太棒了

我在BaseWebServices中有一个default.aspx,它显示在http和https上。我注意到它显示了默认的消息服务页面。将/GetBasket添加到url会显示404错误

我将包括解决方案中BaseWebServices项目的代码:

IMessage.cs

    using System.Collections.Generic;
    using System.ServiceModel;
    using System.ServiceModel.Web;

    namespace BaseWebServices
    {
        // NOTE: The interface name "IMessage" here must match the references to "IMessage" in Web.config.
        // NOTE 2: Parameters must be string data type when using UriTemplate
        [ServiceContract]
        public interface IMessage
        {
            [OperationContract]
            [WebInvoke(
                Method = "GET",
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.WrappedRequest,
                UriTemplate = "GetBasket")]
            List<BasketItemDTO> GetBasket();
        }
    }
使用System.Collections.Generic;
使用System.ServiceModel;
使用System.ServiceModel.Web;
命名空间BaseWebServices
{
//注意:此处的接口名称“IMessage”必须与Web.config中对“IMessage”的引用相匹配。
//注2:使用UriTemplate时,参数必须是字符串数据类型
[服务合同]
公共接口IMessage
{
[经营合同]
[WebInvoke(
Method=“GET”,
ResponseFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.WrappedRequest,
UriTemplate=“GetBasket”)]
列出GetBasket();
}
}
Message.svc

    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;
                }

            }
    }
使用系统;
使用系统配置;
使用System.Collections.Generic;
使用System.ServiceModel.Activation;
使用系统文本;
命名空间BaseWebServices
{
//注意:如果在此处更改类名“Message”,还必须在Web.config和关联的.svc文件中更新对“Message”的引用。
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Required)]
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults=true)]
公共类消息:IMessage
{
私有字符串DBConn{get;set;}
公共信息()
{
DBConn=ConfigurationManager.AppSettings[“DBConn”];
}
公共列表GetBasket()
{
尝试
{
var customerController=new BaseWeb.BaseCustomer.customerController(DBConn);
int customerId=customerController.GetCustomerIdFromCookie();
如果(customerId!=0)
{
var shoppingCartController=新的shoppingCartController(DBConn);
var result=shoppingCartController.GetShoppingCart((int)customerId);
返回结果;
}
其他的
返回新列表();
}
抓住
{
投掷;
}
}
}
web.config

    <?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>


非常感谢您提供的任何帮助或指出我忽略的明显事实。我昨天花了一整天的时间尝试各种配置来实现这一点。这是我第一次发布这样的帖子,所以如果我做了一些愚蠢的事情,请指出它,我会纠正它。

您能在这个网站下放置一个default.aspx页面,并尝试浏览它,然后看到我吗它能在http和https上正常工作。你能在这个网站下放置一个default.aspx页面,并尝试浏览它,看看它能不能正常工作。它能在http和https上正常工作。