简体   繁体   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'

I have a few ASP.NET website and I am trying to set up a WCF service as a membership provider. 我有一些ASP.NET网站,我正在尝试将WCF服务设置为成员资格提供程序。 I want the WCF service to handle all the membership/role details. 我希望WCF服务处理所有成员资格/角色详细信息。 Logging in/out of one will automatically log in/out of the others, so they will all use this service and I want to keep the code all in one place, rather than each site individually. 登录/注销一个将自动登录/注销另一个,因此他们都将使用此服务,我想将代码全部保留在一个位置,而不是每个站点单独保存。 The service still uses the standard Sql Membership provider. 该服务仍使用标准的Sql Membership提供程序。

I get the error in the title when I try to call 尝试致电时,标题出现错误

Membership.ValidateUser(username, password);

from the website. 从网站。 Is there a way to specify the content type, either on the service or the client? 是否可以在服务或客户端上指定内容类型?

Server app.config: 服务器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>

Server Contract: 服务器合同:

[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);
    }
}

Then on the client side, in the web.config: 然后在客户端的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>

What I want to do is, in the login page code behind, call Membership.ValidateUser to log the user in, like so: 我想做的是,在后面的登录页面代码中,调用Membership.ValidateUser来登录用户,如下所示:

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

Can I force the server to accept Json or force the client to send XML? 我可以强制服务器接受Json还是强制客户端发送XML?

Try adding [WebInvoke] attribute after your [OperationContract] attribute 尝试在[OperationContract]属性之后添加[WebInvoke ]属性

something like this 像这样的东西

[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; - WCF ERROR: (415) content type 'application/x-www-form-urlencoded' was not the expected type 'application/soap+xml; charset=utf-8' 收到错误消息,客户端发现响应内容类型为&#39;text / html; charset = utf-8”,但预期为“ application / soap + xml”? - Getting the error Client found response content type of 'text/html; charset=utf-8', but expected 'application/soap+xml'? wcf +响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8) - wcf + The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8) SILVERLIGHT WCF问题:内容类型application / soap + xml; charset = utf-8已发送到需要text / xml的服务; - SILVERLIGHT WCF Issue: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; HTTP 415 无法处理消息,因为内容类型为“application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理消息,因为内容类型为 &#39;application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理该消息,因为内容类型“ application / xml”不是预期的类型“ application / soap + xml”; 字符集= utf-8&#39; - Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 ' 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8), WCF HTTP / 1.1 415无法处理消息,因为内容类型为&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;text / xml; 字符集= UTF-8&#39; - HTTP/1.1 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM