簡體   English   中英

WCF成員資格提供程序引發錯誤:內容類型'application / json; charset = utf-8'不是預期的類型'application / soap + xml; 字符集= UTF-8'

[英]WCF Membership Provider throws error: content type 'application/json; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'

我有一些ASP.NET網站,我正在嘗試將WCF服務設置為成員資格提供程序。 我希望WCF服務處理所有成員資格/角色詳細信息。 登錄/注銷一個將自動登錄/注銷另一個,因此他們都將使用此服務,我想將代碼全部保留在一個位置,而不是每個站點單獨保存。 該服務仍使用標准的Sql Membership提供程序。

嘗試致電時,標題出現錯誤

Membership.ValidateUser(username, password);

從網站。 是否可以在服務或客戶端上指定內容類型?

服務器app.config:

<connectionStrings>
  <clear/>
  <add name="LocalSqlServer" connectionString="SQL_Db_With_Membership_info" providerName="System.Data.SqlClient"/>
</connectionStrings>

<system.web>
  <membership defaultProvider="SqlMembershipProvider">
    <providers>
      <clear/>
      <add name="SqlMembershipProvider"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="LocalSqlServer" />
    </providers>
  </membership>
</system.web>

<system.serviceModel>
  <services>
    <service behaviorConfiguration="AspNetMembership"
        name="Login.LoginService">
      <endpoint address="" binding="wsHttpBinding" 
              bindingConfiguration="LoginBinding"
              name="LoginEndpoint"
              contract="Login.ILoginService">
      </endpoint>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8733/Design_Time_Addresses/Membership/MembershipService/" />
        </baseAddresses>
      </host>
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="AspNetMembership">
      <serviceCredentials>
        <serviceCertificate findValue="CN=tempCert" />
        <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" 
                                membershipProviderName="SqlMembershipProvider" />
        </serviceCredentials>
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <bindings>
    <wsHttpBinding>
      <binding name="LoginBinding">
      </binding>
    </wsHttpBinding>
  </bindings>
</system.serviceModel>

服務器合同:

[ServiceContract]
public interface ILoginService
{
    [OperationContract]
    bool ValidateUser(string username, string password);
}

public class LoginService : ILoginService
{
    public bool ValidateUser(string username, string password)
    {
        return Membership.ValidateUser(username, password);
    }
}

然后在客戶端的web.config中:

<system.web>
  <membership defaultProvider="ClientAuthenticationMembershipProvider">
    <providers>
      <clear/>
      <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="http://localhost:8733/Design_Time_Addresses/Membership/MembershipService/" />
    </providers>
  </membership>
</system.web>

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="LoginEndpoint" />
    </wsHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:8733/Design_Time_Addresses/Membership/MembershipService/" binding="wsHttpBinding" bindingConfiguration="LoginEndpoint" contract="LoginService.ILoginService" name="LoginEndpoint" >
    </endpoint>
  </client>
</system.serviceModel>

我想做的是,在后面的登錄頁面代碼中,調用Membership.ValidateUser來登錄用戶,如下所示:

protected void L1_Authenticate(object sender, AuthenticateEventArgs e)
{
    // THIS IS WHERE THE ERROR HAPPENS
    Membership.ValidateUser(L1.UserName, L1.Password);
}

我可以強制服務器接受Json還是強制客戶端發送XML?

嘗試在[OperationContract]屬性之后添加[WebInvoke ]屬性

像這樣的東西

[WebInvoke(Method = "GET",
           RequestFormat = WebMessageFormat.Json,
           ResponseFormat = WebMessageFormat.Json]

暫無
暫無

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

相關問題 WCF錯誤:(415)內容類型&#39;application / x-www-form-urlencoded&#39;不是預期類型&#39;application / soap + xml; 字符集= UTF-8&#39; 收到錯誤消息,客戶端發現響應內容類型為&#39;text / html; charset = utf-8”,但預期為“ application / soap + xml”? wcf +響應消息的內容類型text / html與綁定的內容類型不匹配(application / soap + xml; charset = utf-8) SILVERLIGHT WCF問題:內容類型application / soap + xml; charset = utf-8已發送到需要text / xml的服務; HTTP 415 無法處理消息,因為內容類型為“application/json; charset=utf-8&#39; 不是預期的類型 &#39;text/xml; 字符集=utf-8&#39; 無法處理消息,因為內容類型為 &#39;application/json; charset=utf-8&#39; 不是預期的類型 &#39;text/xml; 字符集=utf-8&#39; 無法處理該消息,因為內容類型“ application / xml”不是預期的類型“ application / soap + xml”; 字符集= utf-8&#39; 響應消息的內容類型 application/xml;charset=utf-8 與綁定的內容類型(text/xml; charset=utf-8)不匹配,WCF HTTP / 1.1 415無法處理消息,因為內容類型為&#39;application / json; charset = utf-8&#39;不是預期的類型&#39;text / xml; 字符集= UTF-8&#39; 響應消息的內容類型application / xml; charset = utf-8與綁定的內容類型不匹配(text / xml; charset = utf-8)
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM