MTOM Interoperability between Oracle Application Server and Windows Communication Foundation Part2: From Oracle to WCF

By Jesus Rodriguez 

This article is part of a series intended to illustrate WS-* protocols interoperability scenarios between Windows Communication Foundation (WCF) and different J2EE Web Services platforms. Particularly this article focus on MTOM interoperability between WCF and Oracle Application Server v10.1.3.

Binary data exchange using MTOM is a unique Web Services interoperability case given the specific problems that it tackles.  Other WS-* protocols presents a broader set of options allowing one to achieve different levels of interoperability. MTOM on the other hand is an exclusive scenario; services can either be or not be optimized with MTOM, but there is no intermediate level. This is why bidirectional MTOM interoperability between technologies is so important.

The first part of this article illustrated a MTOM interoperability scenario between a WCF client and an Oracle App Server Web Service.  The following section presents a complementary scenario using an Oracle App Server client and a WCF Service.

Implementation: Building a WCF Service that uses MTOM

The following code shows a WCF service that returns the contents of a file as a binary array.

[ServiceContract()]

    public interface IFileService

    {

        [OperationContract()]

        byte[] GetImg(string path);

    }

    public class FileService : IFileService

    {

        public byte[] GetImg(string path)

        {

            return File.ReadAllBytes(path);

        }

    }

To optimize the message exchange for this service using MTOM we need to configure the MTOM Encoding Binding element as part of the customBinding. In addition, to guarantee interoperability with Oracle App Server, the service should be configured to use Soap 1.2.

          <system.serviceModel>

                    <services>

                             <service name="wcfService.FileService" behaviorConfiguration="returnFaults">

                                      <host>

                                                <baseAddresses>

                                                          <add baseAddress="service address…"/>

                                                </baseAddresses>

                                      </host>

                                      <endpoint contract="wcfService.IFileService" binding="customBinding" bindingConfiguration="ProviderBinding" address="wcfmtomws"/>

                             </service>

                   </services>

                   <bindings>

                             <customBinding>

                                      <binding name="ProviderBinding">

                                                <mtomMessageEncoding  messageVersion="Soap12" />

                                                <httpTransport manualAddressing="false" maxBufferPoolSize="524288"

                        maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"

                        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                        keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"

                        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"

                        useDefaultWebProxy="true" />

                                      </binding>

                             </customBinding>

                   </bindings>

                   <behaviors>

                             <serviceBehaviors>

                                      <behavior name="returnFaults" >

                                                <serviceMetadata httpGetEnabled="true" />

                                                <serviceDebug includeExceptionDetailInFaults="true" />

                                      </behavior>

                             </serviceBehaviors>

                   </behaviors>

          </system.serviceModel>

Implementation: Building an Oracle App Server client that uses MTOM

As we explained in the first part of this article, Oracle Application Server supports MTOM as part of its 10.1.3.1 release. The first step to create an MTOM client for the WCF service created on the previous section is to generate the proxy using the Web Service Proxy Wizard included in JDeveloper or the corresponding command-line tool. In order to interface with WCF using MTOM, the client code should set the MTOM_SUPPORT property to “True” either programmatically or using the configuration file. The following code shows a sample client that interacts with the WCF service created in the previous section.

    public static void CallWS()

    {

    try

    {

        wsprj.proxy.WSHttpBinding_IFileServiceClient binding = new wsprj.proxy.WSHttpBinding_IFileServiceClient();

        IFileService proxy= binding.getPort();

        ((OracleStub)proxy)._setProperty(ClientConstants.MTOM_SUPPORT, true);

         byte[] result= binding.getImg(file path…);

         System.out.println(result.length);

    }

    catch(Exception ex){}

    }

Running this client will produce the following SOAP request and response messages. As you might notice, the response message is optimized using MTOM.

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://tempuri.org/"><env:Body><ns0:GetImg><ns0:path>c:\temp\test2.file</ns0:path></ns0:GetImg></env:Body></env:Envelope>

SOAP request produced by the Oracle client

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Body><GetImgResponse xmlns="http://tempuri.org/"><GetImgResult><xop:Include href="cid:http%3A%2F%2Ftempuri.org%2F1%2F633013057872812500" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></GetImgResult></GetImgResponse></s:Body></s:Envelope>

SOAP response produced by the WCF service

Where are we?

MTOM provides a standard and an optimized mechanism to represent binary data in a SOAP envelope. The two parts of this article explained how to achieve MTOM interoperability between Microsoft WCF and Oracle Application Server. The first part explored an interoperability scenario using a WCF client and an Oracle App Server Web Service. This second part has complemented that scenario using a WCF Service with an Oracle App Server client.

No Comments