C# 使用NTLM身份验证的HTTP Web服务

C# 使用NTLM身份验证的HTTP Web服务,c#,web-services,asmx,C#,Web Services,Asmx,我们正在尝试创建一个Web服务,该服务将通过HTTP(而不是HTTPS)使用,并使用NTLM/Windows身份验证。不幸的是,我们似乎找不到“完美”的组合。无论我们尝试什么,使用Windows身份验证似乎总是想强迫我们使用HTTPS;而且使用HTTP似乎忽略了Windows身份验证的所有尝试 以下是我们目前的app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system

我们正在尝试创建一个Web服务,该服务将通过HTTP(而不是HTTPS)使用,并使用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创建一个新绑定,但这也不起作用。有人能给我们指出正确的方向吗?

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

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


还要确保服务器和客户端配置同步

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

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="internalBehaviour">
      <serviceAuthenticationManager authenticationSchemes="Ntlm"/>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
然后在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>

你可能需要


希望这能为您节省一些时间。

这似乎对我们不起作用。您能更具体地说一下“服务器配置”是什么意思吗?ASMX文件没有任何类型的配置文件。(正如您可能知道的,我对web服务没有太多经验,因此非常感谢您的帮助)asmx?啊,我还以为你在服务部门工作呢。您正在试验的配置设置适用于WCF服务,而不是ASMX服务。看到答案,谢谢这两个的链接-我会更仔细地关注WCF文章,看看是否有我遗漏的东西。它在Visual Studio开发服务器上运行得很好,但是当我切换到IIS时,会出现很多问题:405个错误、更多的身份验证问题等等。所有这些都超出了原始问题的范围。谢谢你的帮助!自从您提到您正在尝试使用.asmx webservices以来,我重新标记了这个。您是否知道asmx是一种不应用于新开发的遗留技术?您应该使用WCF来创建服务,因为您已经在使用WCF来使用它。不,我不知道。我们现在切换到WCF,它可以在VisualStudio中使用开发服务器,但不能在IIS中使用。
<services>
       <service behaviorConfiguration="internalBehaviour" name="Corp.WebServices.CorePricingService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="internal" name="ConveyancingEndpoint" contract="Corp.Core.Interfaces.ICorePricingService" />
  </service>
<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>
<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>