Web サービスを .Net 1.1 から WCF にアップグレードしています。新しい Web サービスに接続するクライアントは Web サービスそのものであり、WSE3 を使用して設計されています。私はその Web サービスを制御できず、変更されることはありません。
そのことを念頭に置いて、同じサービス エンドポイントとセキュリティを維持する必要があったため、wscf.blue (最初に wsdl) を使用してこの WCF サービスを設計しました。クライアントが X509 メッセージ暗号化コードをコメントアウトすると、Web サービスは適切に通信します。ただし、X509 暗号化をそのままにしておくと、次のメッセージが表示されます。
「名前空間 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' のヘッダー 'Security' は、この受信者によって理解されませんでしたこのエラーは通常、このメッセージの送信者が受信者が処理できない通信プロトコルを有効にしていることを示します. クライアントのバインディングの構成がサービスのバインディングと一致していることを確認してください. : システムで.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage メッセージ、WebResponse 応答、ストリーム responseStream、ブール値の asyncCall) System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) で"
私のサービスでは、カスタム エンドポイント動作にメッセージ インスペクタを追加し、AfterReceiveRequest が起動されましたが、実際の Web サービスのメソッド呼び出しには到達しませんでした。
web.config を変更する必要があると思いますが、従来の WSE3 Web サービスが理解できるように変更する方法がわかりません。どんなアイデアも役に立ちます:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviorUnsecure">
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" x509FindType="FindByThumbprint" findValue="xx 11 bb xx as bd ef ag r2 xx xx xx xx xx xx 12 34 56 78 90"/>
</serviceCredentials>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="TestContextEndpointBehavior">
<TestContextEndpointBehaviorExtensionElement />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WebSoap" 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="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyWebservice.MyNamespace.WebSoap" behaviorConfiguration="ServiceBehaviorUnsecure">
<endpoint address="http://localhost:6380/WebSoap.svc" behaviorConfiguration="TestContextEndpointBehavior"
binding="basicHttpBinding" bindingConfiguration="WebSoap"
contract="IWebSoap" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="TestContextEndpointBehaviorExtensionElement"
type="MyWebService.TestContextEndpointBehaviorExtensionElement, MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
**編集* *
クライアントから、古い Web サービスの SOAP ヘッダーを保護するために接続するために行っていたことに関するコードの一部を取得することができました。役立つと思われるWeb ページも見つけましたが、さらに疑問が残ります。認証モードを選択するように記載されています。1 つのオプションは、AnonymousForCertificate と別の相互証明書です。表示するページでこれらのオプションのいずれかを選択すると、列挙型が表示され、可能性のあるものは CertificateOverTransport です。これらの 3 つのいずれかが役立つかどうかはわかりません。たとえば、SSL を使用しているため、CertificateOverTransport は実行可能に見えますが、X.509 バージョン 3 証明書が必要であると表示されます。X509 のバージョンを知るにはどうすればよいですか? たぶん、以下のコードが私を助けるのに役立ちます:
public bool EncryptAndSignMessage(string sSigningMachine, string sEncryptingMachine, ref SoapContext scSoapContext)
{
//sSigningMachine is the WSE client's machine name and sEncryptingMachine is my WCF's IIS server machine.
//For breavity, removed code to get byHasCodeSigning and byHashCodeEncrypting values. These are essentially the thumprints for the WSE's server's certificate and my WCF's server certificate.
X509SecurityToken securityTokenForSigning = this.GetSecurityTokenForSigning(byHashCodeSigning);
X509SecurityToken securityTokenForEncrypting = this.GetSecurityTokenForEncrypting(byHashCodeEncryption);
// SPECIFY TIME-TO-LIVE (TTL) FOR SOAP MESSAGE TO MINIMIZE RISK OF SOMEONE INTERCEPTING AND REPLAYING IT
scSoapContext.Security.Timestamp.TtlInSeconds = 60;
// ADD THE CLIENT'S X.509 CERTIFICATES TO THE WS-SECURITY SOAP HEADER
scSoapContext.Security.Tokens.Add(securityTokenForSigning);
scSoapContext.Security.Tokens.Add(securityTokenForEncrypting);
// CREATE NEW INSTANCE OF THE MESSAGE SIGNATURE CLASS AND ADD THE DIGITAL SIGNATURE TO THE WS-SECURITY SOAP HEADER
MessageSignature sig = new MessageSignature(securityTokenForSigning);
scSoapContext.Security.Elements.Add(sig);
// CREATE NEW INSTANCE OF THE ENCRYPTED DATA CLASS AND ADD THE SECURITY TOKEN FOR ENCRYPTING TO THE WS-SECURITY SOAP HEADER
EncryptedData enc = new EncryptedData(securityTokenForEncrypting);
scSoapContext.Security.Elements.Add(enc);
return true;
}
}