3

我们正在尝试创建一个通过 HTTP(不是 HTTPS)使用的 Web 服务,并使用 NTLM/Windows 身份验证。不幸的是,我们似乎找不到那个“完美”的组合。无论我们尝试什么,使用 Windows 身份验证似乎总是想强迫我们使用 HTTPS;并且使用 HTTP 似乎忽略了 Windows 身份验证的所有尝试。

到目前为止,这是我们的 app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="wsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://xyz/xyz/xyzws.asmx" binding="basicHttpBinding"
            bindingConfiguration="xyzwsSoap" contract="xyzws.xyzwsSoap"
            name="xyzwsSoap" />
    </client>
</system.serviceModel>
</configuration>

我们还尝试使用 wsHttpBinding 而不是 basicHttpBinding 创建新绑定,但这也不起作用。谁能指出我们正确的方向?

4

2 回答 2

1

对于 Windows 身份验证,您的安全模式需要设置为TransportCredentialOnly

<security mode="TransportCredentialOnly">
    <transport clientCredentialType="Windows"/>
</security>

还要确保您的服务器和客户端配置是同步的。

于 2012-11-21T18:22:11.213 回答
0

在 Web.config 中的服务器应用程序(托管服务的应用程序)上,system.serviceModel/behaviors/serviceBehaviors您需要创建新的行为。

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="internalBehaviour">
      <serviceAuthenticationManager authenticationSchemes="Ntlm"/>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<system.serviceModel>然后在同一<bindings>节中创建

<bindings>
  <basicHttpBinding>
    <binding name="internal" >
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Ntlm"/>
        </security>
    </binding>
  </basicHttpBinding>
</bindings>

<system.serviceModel>然后在同一<services>节中(您正在配置您试图公开的服务)

<services>
       <service behaviorConfiguration="internalBehaviour" name="Corp.WebServices.CorePricingService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="internal" name="ConveyancingEndpoint" contract="Corp.Core.Interfaces.ICorePricingService" />
  </service>

(明显改变合同)

然后,如果您IIS Express在 Visual Studio(或 IIS)中运行它,请转到applicationhost.config

在 Win7 上:
IISExpress C:\Users\[username]\Documents\IISExpress\config
IIS%WINDIR%\System32\inetsrv\config\applicationHost.config

查找<authentication>您网站的部分将所有内容(但<windowsAuthentication enabled="true">)设置为false并注释掉<!--<add value="Negotiate" />-->(或删除)

<authentication>
            <anonymousAuthentication enabled="false" />
            <basicAuthentication enabled="false" />
            <clientCertificateMappingAuthentication enabled="false" />
            <digestAuthentication enabled="false" />
            <iisClientCertificateMappingAuthentication enabled="false">
            </iisClientCertificateMappingAuthentication>
            <windowsAuthentication enabled="true">
                <providers>
                    <!--<add value="Negotiate" />-->
                <add value="NTLM" />
                 </providers>
            </windowsAuthentication>
        </authentication>

然后在 Web.config 中的客户端应用程序中

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="ConveyancingEndpoint">
      <security mode="TransportCredentialOnly" >
        <transport clientCredentialType="Ntlm"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:53769/CorePricingService.svc" binding="basicHttpBinding" bindingConfiguration="ConveyancingEndpoint" contract="ServiceReference2.ICorePricingService" name="ConveyancingEndpoint"> 
  </endpoint>
</client>

您可能需要在本地计算机上设置 Windows 身份验证

希望这可以节省您一些时间。

于 2015-06-22T10:38:36.690 回答