Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.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
C# 使用SSL加密在IIS 10上托管WCFService库_C#_Asp.net_Wcf_Iis - Fatal编程技术网

C# 使用SSL加密在IIS 10上托管WCFService库

C# 使用SSL加密在IIS 10上托管WCFService库,c#,asp.net,wcf,iis,C#,Asp.net,Wcf,Iis,我正在尝试在IIS 10上使用自签名SSL托管WCF服务库 要获得最少完整的可验证示例,请打开Visual studio 2017 New>Project>C#>Web>WCFLibrary这样,您将得到一个简单的代码,其中有一个操作契约,它接受一个整数并返回一个字符串 现在,我正试图在IIS上使用自签名SSL(我的有更多的操作契约,但这样做就可以了)来承载这个 到目前为止我都试过了 现在下一部分是在IIS上托管它,所以我创建了SVC文件 我的SVC文件包含-> <%@ ServiceHo

我正在尝试在IIS 10上使用自签名SSL托管WCF服务库

要获得最少完整的可验证示例,请打开Visual studio 2017

New>Project>C#>Web>WCFLibrary这样,您将得到一个简单的代码,其中有一个操作契约,它接受一个整数并返回一个字符串

现在,我正试图在IIS上使用自签名SSL(我的有更多的操作契约,但这样做就可以了)来承载这个

到目前为止我都试过了

现在下一部分是在IIS上托管它,所以我创建了SVC文件

我的SVC文件包含->

<%@ ServiceHost Language = "C#" Debug = "true" Service = "WcfServiceLibrary2.Service1" %>

Url是正确的,因为我是通过使用IIS的浏览功能获得的。

简而言之,以下是步骤:

  • 创建自签名证书
  • 添加SSL绑定
  • 为SSL配置虚拟目录
  • 为HTTP传输安全配置WCF服务

  • 此链接更深入:

    首先,请不要将IIS物理路径设置为桌面,这将导致权限问题。我们可以将IIS站点物理路径设置为C分区下的文件夹。
    第二,请阅读以下链接,主要表示WCF服务库项目无法直接发布到IIS,因为IIS无法识别其Appconfig,除非在网站的根目录中手动添加额外的Webconfig。

    一般来说,我们使用包含自动生成的Webconfig文件的WCF服务项目模板,而不是WCF服务库项目模板,因为它通常用作类库。

    默认情况下,该服务由BasicHttpBinding托管,它取决于以下标记。

    <protocolMapping>
            <add binding="basicHttpBinding" scheme="http" />
    </protocolMapping>
    
    
    
    最后,我们可以通过添加一个额外的服务端点来通过https承载服务,请参阅以下配置(简化配置)

    
    


    如果有什么我可以帮忙的,请随时告诉我。

    第一个学分在哪里,我被多个用户指向了正确的方向,所以举几个例子:,,,我的一个同事(在写这个答案之前没有帐户),在这个回答中,我计划介绍使用HTTPS安全性在IIS服务器中托管WCF库可能需要的所有内容

    我使用的工具:

    • Visual Studio 2017专业版
    • IIS 10(随windows 10提供,但必须在windows功能中激活)(见下文)
    第一: 确保已安装visual studio中所需的所有组件

  • Windows->.Net桌面开发
  • Windows->通用Windows开发平台
  • Web与云->ASP.NET与Web开发
  • 在这个列表和其他列表中,可能会包括一些额外的组件,原因是我安装了它们,如果它们是绝对必要的,我无法以这种或那种方式进行验证

    现在,让我们添加必要的windows功能控制面板->程序->打开或关闭Windows功能

    确保进入WCF服务并检查HTTP激活,不要被方块蒙蔽(我的一个错误)

    现在让我们开始创建服务。打开Visual Studio文件->新建->项目->Visual C->Web->WCF->WCF服务库这将生成您试图托管的MCVE

    现在,您必须将其与网站链接,以便生成Web.Config文件和SVC文件,为此,在解决方案资源管理器上,右键单击您的解决方案,Add->New website

    现在在web.config文件中添加

    <system.serviceModel>
        <services>
          <service name="WcfServiceLibrary4.Service1"> <!-- Change the library name as per your need -->
            <endpoint address=""
                      binding="wsHttpBinding"
                      bindingConfiguration="secureHttpBinding"
                      contract="WcfServiceLibrary4.IService1"/> <!-- Change the library name as per your need -->
    
            <endpoint address="mex"
                      binding="mexHttpsBinding"
                      contract="IMetadataExchange" />
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="secureHttpBinding">
              <security mode="Transport">
                <transport clientCredentialType="None"/>
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata 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="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    
    
    
    接下来在网站上添加对服务的引用

    发现服务并添加您创建的服务。现在构建您的解决方案并发布它**小心不要将解决方案发布到桌面或文档等用户目录中,否则ACL权限会让您头疼,而应直接将其发布到驱动器中的目录中

    现在托管时间 首先让我们打开IIS(始终作为管理员)并创建一个新证书

    在服务器上,转到IIS部分并选择服务器证书,然后单击右端的创建新证书

    现在从左侧菜单创建一个新网站

    请确保切换到https并在此处选择您的证书,现在要验证您的服务是否已创建,您需要浏览您的网站创建的svc文件,遗憾的是,此时您将在“/”应用程序中收到一个错误,显示为
    Server error。
    找不到与绑定为BasicHttpBinding的终结点的方案http匹配的基址。注册的基址方案是[https]。
    我无法找到错误的原因,但我能够找到一个绕过它的方法

    绕过此错误的步骤->从左侧菜单中选择网站,在右键菜单上单击绑定,并添加一个HTTP绑定,使用不同的端口。 在此之后,您将能够浏览svc文件的HTTPS版本

    现在,如果您浏览HTTPS链接,您将得到一条消息,即服务已创建

    现在,您可以继续创建使用此服务的应用程序

    未来是什么

  • 我将尝试找到一种不添加额外绑定的方法来实现这一点
  • 第二个目标是在不增加额外网站的情况下实现这一目标

  • 如果我实现了这些,我将进行更新,但是这些不是我现在的优先事项,如果没有任何意义,或者您有任何改进意见,我可能会在很长一段时间内不添加这些内容。

    “但这导致浏览器允许我
    <system.serviceModel>
        <services>
          <service name="WcfService1.Service1" behaviorConfiguration="mybehavior">
            <endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="mybinding">
              <security mode="None">
              </security>
            </binding>
          </basicHttpBinding>
    </bindings>
    
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http"/>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    
    <system.serviceModel>
        <services>
          <service name="WcfServiceLibrary4.Service1"> <!-- Change the library name as per your need -->
            <endpoint address=""
                      binding="wsHttpBinding"
                      bindingConfiguration="secureHttpBinding"
                      contract="WcfServiceLibrary4.IService1"/> <!-- Change the library name as per your need -->
    
            <endpoint address="mex"
                      binding="mexHttpsBinding"
                      contract="IMetadataExchange" />
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="secureHttpBinding">
              <security mode="Transport">
                <transport clientCredentialType="None"/>
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata 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="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>