Khi sử dụng ServiceHost.AddServiceEndpoint để thêm tùy chỉnh ProtoEndpointBehavior tôi nhận được ngoại lệ sau đây:AddServiceEndpoint ném khóa là null?
System.ArgumentNullException: Giá trị không thể null. Tên tham số: chủ chốt tại System.Collections.Generic.Dictionary
2.FindEntry(TKey key) at System.Collections.Generic.Dictionary
2.ContainsKey (key TKey) tại System.ServiceModel.ServiceHostBase.ImplementedContractsContractResolver.ResolveContract (String contractName) tại System.ServiceModel.ServiceHostBase.ServiceAndBehaviorsContractResolver.ResolveContract (String contractName) tại System.ServiceModel.Description.ConfigLoader.LookupContractForStandardEndpoint (string contractName, string serviceName) tại System.ServiceModel.Description.ConfigLoader.LookupContract (string contractName, string serviceName) tại System.ServiceModel.ServiceHostBase.AddServiceEndpoint (ServiceEndpoint endpoi nt) tại My.Service.Business.ServiceHandler.StartService (Loại serviceType, Chuỗi uri, SecureConnectionSettings secureConnectionSettings) trong C: \ My \ Produkter \ My Utveckling \ Solution \ My.Service.Business \ ServiceHandler.cs: line 150
Đây là cách mã trông giống như:
ServiceHost serviceHost = null;
Console.WriteLine("Creating service " + serviceType.FullName);
serviceHost = new MyServiceHost(serviceType, new Uri(uri));
var endPointAddress = "";
HttpBindingBase binding = null;
if (secureConnectionSettings != null && secureConnectionSettings.Enabled)
{
Console.WriteLine("Setting certificates");
X509Store store = new X509Store(secureConnectionSettings.CertificateStore, secureConnectionSettings.CertificateLocation);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, secureConnectionSettings.Thumbprint, true);
store.Close();
if (certs.Count > 0)
serviceHost.Credentials.ServiceCertificate.SetCertificate(secureConnectionSettings.CertificateLocation,
secureConnectionSettings.CertificateStore,
X509FindType.FindByThumbprint,
secureConnectionSettings.Thumbprint);
else
throw new Exception("Could not finde certificate with thumbprint " + secureConnectionSettings.Thumbprint);
endPointAddress = uri + "/BinaryHttpsProto";
binding = CreateNetHttpsBinding(secureConnectionSettings);
}
else
{
endPointAddress = uri + "/BinaryHttpProto";
binding = CreateNetHttpBinding();
}
var endpoint = new System.ServiceModel.Description.ServiceEndpoint(new System.ServiceModel.Description.ContractDescription(typeof(IMyClientService).FullName),
binding,
new EndpointAddress(endPointAddress));
endpoint.EndpointBehaviors.Add(new ProtoBuf.ServiceModel.ProtoEndpointBehavior());
serviceHost.AddServiceEndpoint(endpoint);
Console.WriteLine("Starting service...");
serviceHost.Open();
Console.WriteLine("Service started successfully (" + uri + ")");
return serviceHost;
tôi sử dụng để thiết lập này trong tập tin cấu hình như thế này:
<endpointBehaviors>
<behavior name="protoEndpointBehavior">
<protobuf />
</behavior>
</endpointBehaviors>
Bây giờ, tôi cần phải thêm mã vào mã thay thế.
Điều gì là sai?
Dòng nào trong mã mà bạn đã đăng đang ném lỗi đó? – Sparrow
@FeryalBadili Nó được ném vào dòng endpoint.EndpointBehaviors.Add. – Banshee