首页 > 解决方案 > System.InvalidOperationException: '对象是只读的。' 当通过token SSL证书和token密码消费soap服务时

问题描述

我一直在尝试使用带有密钥库 SSL 客户端证书和密钥库密码的 Web API 来使用肥皂服务,它可以从 SOAP UI 完美运行,即使它在没有 SSL 证书的情况下使用。

PersonService.PersonClient personclient = new PersonService.PersonClient();
// System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope(personclient.InnerChannel);
    X509Certificate2 cert = new X509Certificate2("F:\\Common\\Services\\client certificate.p12", "pwd");
//cert.Import("F:\\Common\\Services\\client certificate.p12", "pwd", X509KeyStorageFlags.DefaultKeySet);

// personclient.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2();
**personclient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "9ee8be61d875bd6e1108c98b590386d0a489a9ca"); ;//("F:\\Common\\Services\\Open Platform OHP Client01202021.p12", "password", X509KeyStorageFlags.DefaultKeySet);**           
    callerInfo callerInfoObj = new callerInfo(); personBean personBeanobj = new personBean(); eoSearchOptions eoSearchOptionsobj = new eoSearchOptions();
callerInfoObj.user = "me";
personBeanobj.username = "rahul";
eoSearchOptionsobj.debug = false;
eoSearchOptionsobj.filterDeactivatedRecords = false;
var probabilisticSearchResult = personclient.searchUser(callerInfoObj, personBeanobj, eoSearchOptionsobj);
return "value";

我可以修改和解决此问题的任何提示。

堆叠比赛

StackTrace " 在 System.ServiceModel.Security.X509CertificateInitiatorClientCredential.ThrowIfImmutable()\r\n 在 System.ServiceModel.Security.X509CertificateInitiatorClientCredential.SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, Object findValue)\r\n 在 testoap.Controllers。 F:\proj\Project\Testsoap\testsoap\testsoap\Controllers\ValuesController.cs 中的 ValuesController.Get(Int32 id):第 40 行\r\n at lambda_method(Closure , Object , Object[] )\r\n at System .Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.b__2(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[]参数)\r\n 在 System.Web.Http.Controllers.ReflectedHttpActionDescriptor。ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancelToken)" 字符串

标签: .netsoap-clientwebapi

解决方案


推荐阅读