[英]C# Object is read-only when assign certificate
我正在嘗試調用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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.