簡體   English   中英

從ASP.NET調用WCF服務時身份驗證失敗

[英]Authentication failed while calling WCF service from ASP.NET

平台:VS 2008,.NET 3.5,C#,Oracle 11g

我創建了一個WCF服務,它接受一些數據元素,然后將它們插入數據庫表並返回一個整數。 我還創建了一個小的ASP.NET Web應用程序來測試該服務。 測試Web應用程序只有一個包含字段和按鈕的頁面,單擊該按鈕實際調用Web服務以插入數據並返回整數值。

我采取的步驟:

  • 構建WCF服務
  • 發布WCF服務
  • 使用svcutil生成代理類(.cs)和app.config
  • 構建測試asp.net應用程序並添加上述步驟中生成的代理類和配置設置。
  • 破壞測試應用程序

當我在我的計算機上部署WCF和測試Web應用程序時,它工作正常 - Windows XP,IIS 5.1。 但是,每當我嘗試在遠程服務器上部署它時,它都不起作用。 當我嘗試使用該服務(部署在遠程服務器上 - Windows 2003服務器,IIS 6)時,我收到以下錯誤:

無法滿足安全令牌請求,因為身份驗證失敗。

描述:執行當前Web請求期間發生未處理的異常。 請查看堆棧跟蹤以獲取有關錯誤及其源自代碼的位置的更多信息。

異常詳細信息:System.ServiceModel.FaultException:無法滿足安全令牌請求,因為身份驗證失敗。

以下是.config文件內容:

調用ASP.NET Web應用程序(Consumer)的Web.Config的wcf部分:

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
    <binding name="WSHttpBinding_IMyWCFService" 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="Text" 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" establishSecurityContext="true" />
      </security>
    </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://57.23.85.28:8001/MyWCFService/MyWCFService.svc"
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyWCFService"
      contract="IMyWCFService" name="WSHttpBinding_IMyWCFService">
    <identity>
      <dns value="localhost" />
    </identity>
      </endpoint>
    </client>
  </system.serviceModel>

WCF的Web.Config:

<configuration>
  <connectionStrings>
    <add name="DSMyWCF" connectionString="Data Source=XXX;User id=XXX;Password=XXX;"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="MyWCFService.MyWCFServiceBehavior"
        name="MyWCFService.MyWCFService">
        <endpoint address="" binding="wsHttpBinding" contract="MyWCFService.IMyWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/MyWCFService/MyWCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyWCFService.MyWCFServiceBehavior">
          <!-- To avoid disclosing metadata information,
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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>
  </system.serviceModel>
</configuration>    

可能與wcf服務的安全配置有關,具體而言,Windows憑據類型需要有效的域用戶名和密碼信息。

嘗試在客戶端上提供以下屬性;

proxy.ClientCredentials.Windows.ClientCredential.UserName = "UserName ";
proxy.ClientCredentials.Windows.ClientCredential.Password = "Password ";
proxy.ClientCredentials.Windows.ClientCredential.Domain = "Domain ";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM