使用已知密码将凭据委派给WCF服务

时间:2011-07-20 06:31:45

标签: .net wcf web-services kerberos delegation

我有一个ASP Web服务,需要与Windows服务托管的WCF端点通信,然后通过Exchange Web服务托管API v1.1与Microsoft Exchange通信

我有这个代码在通过Win Forms应用程序调用时工作正常但在从IIS中的ASP Web服务调用时不起作用:

Dim endpointUri As String = "http://localhost:8000/EWS/Service/"
ewsClient = New EWS.WCFServiceClient("WSHttpBinding_IWCFService", endpointUri)

Dim userName As String = "first.last"
Dim domain As String = "myDomain"
Dim password As String = "abc123"

ewsClient.ClientCredentials.UserName.UserName = userName
ewsClient.ClientCredentials.UserName.Password = password
ewsClient.ClientCredentials.Windows.ClientCredential.UserName = userName
ewsClient.ClientCredentials.Windows.ClientCredential.Domain = domain
ewsClient.ClientCredentials.Windows.ClientCredential.Password = password

Dim result As String = ewsClient.SendTestMessage(uxToAddress.Text)

我曾尝试在域用户帐户下运行IIS,但仍然无法使用来自Exchange的HTTP 401未经授权的例外。

我也尝试过使用WIN32 LogonUser,但这也没有用。

如果我有使用我想要运行的用户名和密码,如何调用需要来自ASP Web服务的委派凭据的wcf服务?

服务器上的绑定:

  <wsHttpBinding>
    <binding name="wsHttpBindingDefault" closeTimeout="00:05:00" receiveTimeout="Infinite" maxReceivedMessageSize="1073741824" messageEncoding="Mtom">
      <readerQuotas maxDepth="32" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
<behaviors>
  <serviceBehaviors>
    <behavior name="EWSBehavior">
      <serviceAuthorization impersonateCallerForAllOperations="true"></serviceAuthorization>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="EWSBehavior" name="EWS.WCFService">
    <endpoint address="" bindingConfiguration="wsHttpBindingDefault" binding="wsHttpBinding" contract="EWS.IWCFService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/EWS/Service/"/>
      </baseAddresses>
    </host>
  </service>
</services>

客户端上的绑定(对于运行良好的WinForms应用程序和无效的ASP Web服务,这是相同的):

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IWCFService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:8000/EWS/Service/" behaviorConfiguration="ImpersonationBehavior" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWCFService" contract="EWS.IWCFService" name="WSHttpBinding_IWCFService">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
</client>
<behaviors>
  <endpointBehaviors>
    <behavior name="ImpersonationBehavior">
      <clientCredentials>
        <windows allowNtlm="true" allowedImpersonationLevel="Delegation"/>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

0 个答案:

没有答案