c# - 分配证书时 C# 对象是只读的
问题描述
我正在尝试调用 WSDL 文件提供的 Web 服务。
在将 WSDL 添加为服务引用并指向我的计算机上 WSDL 文件的位置之后。
使用代码我尝试将证书分配给 Web 服务,如下所示:
NeqatyService.NeqatyWSAPIPortTypeClient mPortType = new NeqatyWSAPIPortTypeClient();
Byte[] rawData = File.ReadAllBytes(@"c:\cert.p12");
String cert64 = Convert.ToBase64String(rawData);
X509Certificate2 certificates = new X509Certificate2(rawData, "pass", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.UserKeySet);
mPortType.ClientCredentials.ClientCertificate.Certificate = certificates;
调试器在此行引发错误:
mPortType.ClientCredentials.ClientCertificate.Certificate = certificates;
说明:对象是只读的
我想注意到,我曾经使用提供证书和密码的 SOAPUI 调用 Web 服务,并且它有效。
任何人都可以帮我解决这个问题。
解决方案
尝试在绑定配置中将 messageEncoding 的值修改为“Mtom”。这是我最近使用的配置示例。当值设置为“文本”时,我收到了该错误。
<binding name="AWDProcessingServiceBinding" closeTimeout="00:01:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="655360" maxBufferPoolSize="524288" maxReceivedMessageSize="655360"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="Basic"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
推荐阅读
- python - 试图删除烧瓶中的所有表,RuntimeError: No application found。在视图函数中工作或推送应用程序上下文
- indexing - 如何在“if”函数中将整数转换为索引?
- kotlin - kaptGenerateStubsKotlin,CreateProcess 错误=206
- objective-c - 使用手势在 ARSCNView 中移动 SCNNode
- python - 如何在单个日期创建具有多个起点和终点的条形图?
- python - 如何使用 Selenium 将鼠标悬停在多个元素上并通过 Python 提取文本
- python-3.x - 如何模拟返回用户对象的函数
- swift - App Store Connect:ITMS-90492:无效的 WatchKit 支持
- php - MongoDb + PHP:不能指定多个位置项目。每个查询
- python-3.x - 如何在 selenium python 中运行多个测试用例?