我正在实现一个必须使用Java Web服务的c#webservice客户端。通信协议是https,并且必须通过证书(包括私钥)进行身份验证。
据我所知,私钥的目的是识别Web服务背后的正确客户数据库。
我不知道证书文件的格式,因为它的文件扩展名是“txt”。如果我尝试通过mmc控制台在Windows证书存储区中导入此文件,则会出现“无法识别文件类型”的错误(我将其翻译为德语,因此英语听起来可能略有不同)。所以我的客户端应用程序无法使用它在证书库中找不到的证书。
我尝试实例化证书并将文件位置传递给构造函数。
mVerifyCert = new X509Certificate2(AppConfig.Settings.Default.CertificateAndKeyFileFullName);
但随后发生以下异常(英文版可能是“System.Security.Cryptography.CryptographicException:找不到对象。”
{System.Security.Cryptography.CryptographicException:Das angeforderte Objekt wurde nicht gefunden。
bei System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) bei System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName) bei System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName,Object password,X509KeyStorageFlags keyStorageFlags) bei System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName) bei System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName)
所以现在人们可能会认为该文件存在问题。但是当这个文件与SoapUI Tool一起使用来测试web服务时,它可以正常工作。 我也hava java示例客户端应用程序使用此文件与java信任存储区,它适用于Java客户端。
我还尝试将文件扩展名从“txt”更改为“p12”,“pem”,以便能够将文件导入Windows证书库,但没有成功。
你能告诉我这里的问题是什么吗?我该怎么做才能解决这个问题。我根本不知道。
这是我的app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="QcsiSync.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<QcsiSync.Properties.Settings>
<setting name="DefactInstanceXmlFileNameFull" serializeAs="String">
<value>..\..\Data\getDefactInstance.xml</value>
</setting>
<setting name="DefactInstanceXmlDotNet" serializeAs="String">
<value>..\..\Data\DefactInstanceXmlDotNet.xml</value>
</setting>
<setting name="WebServiceUrl" serializeAs="String">
<value>https://xyz.com/wsAdapter</value>
</setting>
<setting name="CertificateFileFullName" serializeAs="String">
<value>..\..\Data\sdm.crt</value>
</setting>
<setting name="CertificateAndKeyFileFullName" serializeAs="String">
<value>..\..\Data\sdmCert + key.txt</value>
</setting>
<setting name="QcSupplierUrl" serializeAs="String">
<value>https://xyz.net/qcbin</value>
</setting>
<setting name="QcSupplierUsername" serializeAs="String">
<value>xyz</value>
</setting>
<setting name="QcSupplierPassword" serializeAs="String">
<value>xyz</value>
</setting>
<setting name="QcSupplierDomain" serializeAs="String">
<value>xyz</value>
</setting>
<setting name="QcSupplierProjetName" serializeAs="String">
<value>xyz</value>
</setting>
</QcsiSync.Properties.Settings>
</userSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WSAdapterBFPortBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="WSAdapterBFPortBinding1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
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="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<!--<binding name="WSAdapterBFPortBinding2" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>-->
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8890/wsAdapter" binding="basicHttpBinding"
bindingConfiguration="WSAdapterBFPortBinding" contract="QcsiWS.WSAdapterBCI"
name="WSAdapterBFPortHttp" />
<endpoint address="https://xyz.com/wsAdapter"
binding="basicHttpBinding" bindingConfiguration="WSAdapterBFPortBinding1"
contract="QcsiWebService.WSAdapterBCI" name="WSAdapterBFPortHttps" />
</client>
</system.serviceModel>
</configuration