叫我的服務,當我得到這個錯誤:WCF已知類型錯誤
Server Error in '/' Application.
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: There was an error while trying to serialize parameter http://DSD.myCompany.net/DsdWebServices/2011/05/:config. The InnerException message was 'Type 'System.OrdinalComparer' with data contract name 'OrdinalComparer:http://schemas.datacontract.org/2004/07/System' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
Source Error:
Line 130: passwordAttemptWindow="10"
Line 131: passwordStrengthRegularExpression=""
Line 132: type="DsdWebsite.Providers.DsdMembershipProvider, DsdWebsite.Providers" />
Line 133: </providers>
Line 134: </membership>
Source File: C:\Development\DSD Website\WebUI\web.config Line: 132
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5444; ASP.NET Version:2.0.50727.5420
的服務是成員資格提供數據服務。我創建了一個MembershipUser DTO來在整個服務中來回移動數據。它只使用標準類:string,int,DateTime。我使用guid而不是objectUserKey作爲對象。
該服務的界面看起來是這樣的:
[ServiceContract(Namespace = "http://DSD.myCompany.net/DsdWebServices/2011/05/")]
[ServiceKnownType(typeof(MembershipUserDTO))]
[ServiceKnownType(typeof(NameValueCollection))]
[ServiceKnownType(typeof(Guid))]
[ServiceKnownType(typeof(DateTime))]
public interface IDsdMembershipProviderService
{
[OperationContract]
void Initialize(string name, NameValueCollection config);
[OperationContract]
MembershipUserDTO CreateUser(string username,
string salt,
string encodedPassword,
...
的DTO看起來像這樣
namespace DsdWebsite.Services.Providers
{
[Serializable]
[DataContract]
[KnownType(typeof(Guid))]
[KnownType(typeof(DateTime))]
public class MembershipUserDTO
{
public MembershipUserDTO(string providerName, string userName, Guid providerUserKey, string email,
string passwordQuestion, string comment, bool isApproved, bool isLockedOut,
DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate,
DateTime lastPasswordChangedDate, DateTime lastLockoutDate,
string firstName, string lastName, string cellPhone, string officePhone,
string brokerId, bool isAdmin, bool mustChangePassword)
{
ProviderName= providerName;
UserName = userName;
ProviderUserKey= providerUserKey;
Email= email;
PasswordQuestion= passwordQuestion;
Comment= comment;
IsApproved=isApproved;
IsLockedOut= isLockedOut;
CreationDate= creationDate;
LastLoginDate= lastLoginDate;
LastActivityDate= lastActivityDate;
LastPasswordChangedDate = lastPasswordChangedDate;
LastLockoutDate=lastLockoutDate;
...
最後,我的web.config看起來是這樣的:
<membership
defaultProvider="DsdMembershipProvider"
userIsOnlineTimeWindow="15"
hashAlgorithmType=""> <providers>
<clear/>
<add
name="DsdMembershipProvider"
connectionStringName="DsdMembershipConnectionString"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/DsdWebsite/"
requiresUniqueEmail="true"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
type="DsdWebsite.Providers.DsdMembershipProvider,
DsdWebsite.Providers" />
</providers> </membership>
如何我可以確定導致錯誤的類型或對象嗎? 感謝
我無法找到System.OrdinalComparer - 來自哪裏? – 2011-05-31 17:28:33
@Terry:我會在短時間內更新信息。 – 2011-05-31 17:34:03
總猜測:右鍵單擊服務參考,單擊配置服務參考,使用集合類型和字典集合類型下拉框。 – 2011-05-31 19:26:49