我正面临着我难以理解的问题。我尝试做的是创建WCF服务。在此服务上,我尝试在服务器和客户端使用证书进行身份验证。这是我的代码和例外列表。
System.FormatException:Base-64 char数组的长度无效或 串。在System.Convert.FromBase64_Decode(Char * startInputPtr, Int32 inputLength,Byte * startDestPtr,Int32 destLength)at System.Convert.FromBase64CharPtr(Char * inputPtr,Int32 inputLength)
在System.Convert.FromBase64String(String s)at System.ServiceModel.Description.ConfigLoader.LoadIdentity(IdentityElement 元素) System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host,ServiceDescription描述,ServiceElement serviceElement, Action`1 addBaseAddress,Boolean skipHost)at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader,ServiceDescription描述,ServiceElement serviceSection)at System.ServiceModel.ServiceHostBase.ApplyConfiguration()at System.ServiceModel.ServiceHost.ApplyConfiguration()at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)at System.ServiceModel.ServiceHost.InitializeDescription(类型 serviceType,UriSchemeKeyedCollection baseAddresses)at System.ServiceModel.ServiceHost..ctor(类型serviceType,Uri [] baseAddresses)at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind亲切) Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo 信息)
namespace Test
{
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
class TestService:ITestUser
{
public string Print(string text)
{
return "You've printed: " + text;
}
}
}
namespace Test
{
[DataContract]
public class TestUser
{
[DataMember]
string Username;
[DataMember]
string Password;
}
}
namespace Test
{
[ServiceContract]
public interface ITestUser
{
[OperationContract]
string Print(string text);
[OperationContract]
bool Authorise(string Username, string Password);
}
}
App.Config中
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service
behaviorConfiguration="CustomBehaviour"
name="Test.TestService">
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="SecureBinding"
contract="Test.ITestUser"
name="TestSecureEndPoint"
isSystemEndpoint="true">
<identity>
<certificate encodedValue="TestCertificate" />
<certificateReference isChainIncluded="true" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/TestService/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="SecureBinding">
<security mode="Message">
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CustomBehaviour">
<serviceMetadata httpGetEnabled="True"/>
<serviceCredentials>
<clientCertificate>
<authentication
certificateValidationMode="ChainTrust"
revocationMode="NoCheck"/>
</clientCertificate>
<serviceCertificate
findValue="TestCertificate"
x509FindType="FindBySubjectName"
storeLocation="LocalMachine"
storeName="TrustedPublisher"/>
</serviceCredentials>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>