[英]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.