Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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
.net 具有用户名和密码的WCF服务_.net_Wcf_Web Services_Wcf Security - Fatal编程技术网

.net 具有用户名和密码的WCF服务

.net 具有用户名和密码的WCF服务,.net,wcf,web-services,wcf-security,.net,Wcf,Web Services,Wcf Security,在使用用户名和密码时,WCF服务有一些新功能。为了使用用户名和密码保护我的web服务,我遵循了在上找到的教程 我的配置文件在下面 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.web> <compilation debug="false" targetFramework="4.5" /> <httpRuntime targetFramewo

在使用用户名和密码时,WCF服务有一些新功能。为了使用用户名和密码保护我的web服务,我遵循了在上找到的教程

我的配置文件在下面

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <system.web>
    <compilation debug="false" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="NewBehavior0" name="TService">
        <endpoint address="mex" binding="mexHttpBinding" contract="ITechnology" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="NewBinding0">
          <security>
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior0">
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust" />
            </clientCertificate>
            <serviceCertificate findValue="Server" storeLocation="CurrentUser"
          storeName="TrustedPeople" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TService, Services1"/>
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

现在,我可以在浏览器中查看WDSL,并且我知道证书在本地可以正常工作。当我使用WCF测试工具连接到服务时,它不会提示我输入用户名和密码

根据我发布的链接和下面的链接,我甚至没有完成最后一步(添加代码以传递用户名和密码),但我仍然可以连接到该服务并检索所有数据

我遗漏了什么?如果只有用户名和密码允许用户/服务检索数据,我如何限制服务

编辑1:

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="NewBehavior0" name="TechService">
        <endpoint address="mex" binding="mexHttpBinding" contract="ITechService" />
       <endpoint address="TechService.svc" binding="wsHttpBinding" bindingConfiguration="" contract="ITechService" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="NewBinding0">
          <security>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior0">
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust" />
            </clientCertificate>
            <serviceCertificate findValue="Server" storeLocation="CurrentUser"
              storeName="TrustedPeople" x509FindType="FindBySubjectName" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TechService, Services1"/>
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

根据对链接的CodeProject页面的快速查看,您的配置文件似乎有点不正确(因为它并不表示任何端点实际上正在使用客户端凭据类型)

“NewBinding0”指定clientCredentialType=“Certificate”,但文章指出该值应为:

<binding name="NewBinding0">
    <security mode="Message">
        <message clientCredentialType="UserName"/>
    </security>
</binding>

此外,服务定义仅定义“mex”(元数据)端点。您很可能希望定义wsHttpBinding。。endpoint,它使用指定clientCredentialType=“UserName”的正确绑定


希望这有帮助。

关于,

基于对链接的CodeProject页面的快速查看,您的配置文件似乎有点不正确(因为它并不表示任何端点实际上正在使用客户端凭据类型)

“NewBinding0”指定clientCredentialType=“Certificate”,但文章指出该值应为:

<binding name="NewBinding0">
    <security mode="Message">
        <message clientCredentialType="UserName"/>
    </security>
</binding>

此外,服务定义仅定义“mex”(元数据)端点。您很可能希望定义wsHttpBinding。。endpoint,它使用指定clientCredentialType=“UserName”的正确绑定


希望这有帮助。

关于,

您的服务元素和端点元素的name和contract属性应该是完全限定的名称,即namespace.TService和namespace.ITechnology。根据您的配置,您的端点没有使用正确的绑定机制。它应该是具有传输安全性的wsHttpBinding或basicHttpBinding。您的服务元素和端点元素的名称和约定属性应该是完全限定的名称,即namespace.TService和namespace.ITechnology。根据您的配置,您的端点没有使用正确的绑定机制。它应该是wsHttpBinding或basicHttpBinding,具有传输安全性感谢我编辑了我的原始帖子,并在编辑1中包含了最新的配置文件,但它仍然不能按预期工作。请注意,我的印象是,当我连接到服务时,在连接到服务之前会提示我输入用户名/密码或类似信息?根据Edit 1配置文件,bindingConfiguration似乎仍未设置(bindingConfiguration=“”)。您需要设置bindingConfiguration=“NewBinding0”才能应用绑定安全模式。谢谢,我已经编辑了我的原始帖子,并在编辑1下包含了最新的配置文件,但它仍然无法按预期工作。请注意,我的印象是,当我连接到服务时,在连接到服务之前会提示我输入用户名/密码或类似信息?根据Edit 1配置文件,bindingConfiguration似乎仍未设置(bindingConfiguration=“”)。您需要设置bindingConfiguration=“NewBinding0”才能应用绑定安全模式。