まず、Axis2 でも MTOM を有効にする必要があります。axis2.xml 構成ファイル (WEB-INF/conf/axis2.xml) を見つけて、次の設定を調整します。
<axisconfig name="AxisJava2.0">
<!-- ================================================= -->
<!-- Parameters -->
<!-- ================================================= -->
.../...
<parameter name="enableMTOM">true</parameter>
.../...
</axisconfig>
これがないと、Axis は MTOM をまったく処理できず、クライアントは非常に混乱します。
XOP/MTOM への切り替えは multipart-mime への切り替えも意味し、クライアントは実際に multipart-mime の回答を得たので、結局のところ Axis2 設定は問題ないと思います :) クライアントがプレーンな XML (つまり、素敵な SOAP) を期待しているという事実response) は、クライアント側で MTOM をセットアップしていないことを示します。
BasicHttpBinding を使用していると仮定すると、WCF で MTOM を有効にするには、次のようにします。
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MySOAP11Binding"
...
messageEncoding="Mtom"
...
>
.../...
</binding>
</basicHttpBinding>
.../...
バインディング要素の maxBufferSize、maxBufferPoolSize、および maxReceivedMessageSize 属性も微調整する必要があります。
または、コードでこれを設定できます。
private ServiceProxy<MyPortTypeClient, MyPortType> getClient()
{
EndpointAddress endpoint = new EndpointAddress("http://server/axis/services/My");
// The binding
BasicHttpBinding binding = new BasicHttpBinding();
binding.OpenTimeout = minutes(1);
binding.CloseTimeout = minutes(1);
binding.SendTimeout = minutes(10);
binding.ReceiveTimeout = minutes(10);
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MessageEncoding = WSMessageEncoding.Mtom;
if (binding is BasicHttpBinding)
{
// Also setting to streamed mode
((BasicHttpBinding)(Object)binding).TransferMode = TransferMode.Streamed;
}
binding.AllowCookies = true;
// MyPortType and MyPortTypeClient are implemented in Reference.cs, i.e. this
// code is generated by svcutil or Visual Studio from your WSDL.
MyPortTypeClient _proxy = new MyPortTypeClient(binding, endpoint);
ServiceProxy<MyPortTypeClient, MyPortType> proxy = new ServiceProxy<MyPortTypeClient, MyPortType>(_proxy);
if (!String.IsNullOrEmpty(wsUsername) && !String.IsNullOrEmpty(wsPassword))
{
UserNamePasswordClientCredential credentials = _proxy.ClientCredentials.UserName;
credentials.UserName = wsUsername;
credentials.Password = wsPassword;
}
return proxy;
}
コードでこれを行うことの良い点は、特定のバインディングに設定できるパラメーターに関して、IDE からヘルプが得られることです。BasicHttpBinding からたとえば WSHttpBinding に切り替えると、新しいバインディングと一致しないパラメーターに対してコンパイル エラーが発生します。