一方面,您还必须在 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,您将收到与新绑定不匹配的参数的编译错误。