例: MTOMを使用する
Message Transmission Optimization Mechanism(MTOM)では、メッセージの一部を選択的にバイナリデータとしてエンコードし、SOAPメッセージの送信やワイヤ形式を最適化することができます。
このシナリオ例では、MTOMによるSOAPメッセージエンコードのサポートを追加します。
以下の手順を実行します。
1.Integration Studioでエクステンションを作成し、MTOMを有効にするアクションを定義します。
たとえば、パラメータを持たない「EnableSoapMTOM」というアクションをIntegration Studioで定義しています。
2.[Edit Source Code .NET]をクリックします。プロジェクトのターゲットフレームワークを設定し、System.ServiceModel
アセンブリへの参照を追加します。
以下のコードを入力し、Integration Studioで作成されたMssEnableSoapMTOM
関数プレースホルダを置き換えます。
// required 'using' statements at the beginning of the file using System.Linq; using System.ServiceModel.Channels; using OutSystems.SOAP.API; /* ...*/ // replace the 'MssEnableSoapMTOM' function placeholder with the following code public void MssEnableSoapMTOM() { // Get current request var client = SoapRequest.GetCurrentClient(); // Create a binding based on the one already set-up. var customBinding = new CustomBinding(client.Endpoint.Binding); // Get the TextMessageEncodingBindingElement; // it will be replaced with the MTOM encoding element var textEncodingElement = customBinding.Elements.OfType<TextMessageEncodingBindingElement>().Single(); var mtomEncodingElement = new MtomMessageEncodingBindingElement(client.Endpoint.Binding.MessageVersion, textEncodingElement.WriteEncoding); // Insert MTOM encoding element where TextMessageEncodingBindingElement was // This is necessary to respect the mandatory order of elements in a custom binding: // https://docs.microsoft.com/en-us/dotnet/framework/wcf/extending/custom-bindings customBinding.Elements.Remove(textEncodingElement); customBinding.Elements.Insert(customBinding.Elements.Count - 1, mtomEncodingElement); //Replace previous binding client.Endpoint.Binding = customBinding; }
3.Visual Studio .NETを停止し、Integration Studioに戻ります。Integration Studioで、[1-Click Publish]ツールバーアイコンをクリックするか、またはF5
キーを押して、エクステンションをパブリッシュします。
4.Service Studioで、アプリケーションモジュールにエクステンションのEnableSoapMTOMアクションへの参照を追加します。
5.SOAP WebサービスのSOAPコールバックフロー(OnBeforeRequestAdvanced)で、EnableSoapMTOMアクションをフローにドラッグします。
6.アプリケーションモジュールをパブリッシュし、アプリケーションをテストします。