C# 从WCF服务序列化AspNet.Identity对象
我已经快要疯了,所以我要 我已经将紧密耦合的登录/用户管理系统从MVC5中分离出来,并将其固定在我自己的用户管理服务中,这在通过DLL引用该服务进行测试时非常有效。然而,当涉及到适当的SOA和引用此服务时,我得到了:C# 从WCF服务序列化AspNet.Identity对象,c#,.net,wcf,C#,.net,Wcf,我已经快要疯了,所以我要 我已经将紧密耦合的登录/用户管理系统从MVC5中分离出来,并将其固定在我自己的用户管理服务中,这在通过DLL引用该服务进行测试时非常有效。然而,当涉及到适当的SOA和引用此服务时,我得到了: Type 'Microsoft.AspNet.Identity.UserLoginInfo' cannot be serialized 太棒了。所以我一直在努力摆脱其他对象的序列化错误,但还是坚持这一点 这里是唯一使用它的地方: public LoginResult AddLo
Type 'Microsoft.AspNet.Identity.UserLoginInfo' cannot be serialized
太棒了。所以我一直在努力摆脱其他对象的序列化错误,但还是坚持这一点
这里是唯一使用它的地方:
public LoginResult AddLogin(string userId, LoginInfo info)
{
var createdUser = UserManager.AddLogin(userId, new UserLoginInfo(info.LoginProvider, info.ProviderKey));
return new LoginResult
{
Errors = createdUser.Errors.ToList(),
Succeeded = createdUser.Succeeded
};
如您所见,我无法回避不使用它的问题,但我不会在服务->客户端之间传递它,因此我不知道编译器为什么要序列化它
我试过:
[ServiceKnownType(typeof(UserLoginInfo))]
靠我的服务,运气也不好。我甚至不能添加一个[DataContract],因为它是另一个库的一部分,或者创建一个新对象并从UserLoginInfo继承,因为AddLogin需要该对象
肯定有解决办法吗
编辑
按要求设置我的转换类:
namespace UserManagement.Core.Service
{
[DataContract]
public class LoginResult
{
[DataMember]
public bool Succeeded { get; set; }
[DataMember]
public List<string> Errors { get; set; }
}
[DataContract]
public class LoginInfo
{
[DataMember]
public string ProviderKey { get; set; }
[DataMember]
public string LoginProvider { get; set; }
}
}
服务配置:
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<connectionStrings>
// Removed
</connectionStrings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.3" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.5.3"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
SVC标记:
namespace UserManagement.Core.Service
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public partial class UserManagementService : IUserManagementService
{
private readonly IUnitOfWorkFactory<ApplicationDbContext> _factory;
UnitOfWork<ApplicationDbContext> _context;
/// <summary>
/// AssociationService Constructor
/// </summary>
/// <param name="factory"></param>
public UserManagementService(IUnitOfWorkFactory<ApplicationDbContext> factory)
{
_factory = factory;
// Use the context sent from the web application
if (OperationContext.Current != null)
{
string dbContextName = OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("DatabaseContext", "");
_context = this._factory.Create(dbContextName);
}
else
{
_context = this._factory.Create();
}
}
}
}
发布LoginResult类,那是你的类吗?LoginInfo,那是谁的类?是的,LoginResult是我自己的类,所以我可以用另一个AspNet.Identity类绕过序列化问题。我会在这里发布,但不能100%确定这会干扰UserLoginInfo的原因。在问题编辑中添加了这些。您是在错误之前还是之后添加了[ServiceKnownTypeOfUserLogininfo]吗?我会移除它。。。