SIGN UP MEMBER LOGIN:    
ARTICLE

Sending Binary Data from Oracle Application Server to WCF through MTOM: Part II

Posted by John Charles Olamendy Articles | WCF with C# May 14, 2007
This article will illustrate how to send binary data from Windows Communication Foundation (WCF) to Oracle Application Server (Oracle AS) using Web Services specifications specifically MTOM standard specification, thus achieving interoperability between the two platforms. Some days ago, I blogged information in CSharpCorner blogs about MTOM specifications.
Reader Level:

Introduction.

This article will illustrate how to send binary data from Windows Communication Foundation (WCF) to Oracle Application Server (Oracle AS) using Web Services specifications specifically MTOM standard specification, thus achieving interoperability between the two platforms. Some days ago, I blogged information in CSharpCorner blogs about MTOM specifications.

Implementing MTOM in Windows Communication Foundation (WCF). Creating the server side.

The first to do is to create a solution with a console application and name it WCF_MTOM_Server. Then go to Project | Add New Item and from the Add New Item windows, choose the WCF Service and name the service BinaryFileTransferService to get a very large binary document. Now, let's define the service contract as shown in Listing 1.

[ServiceContract()]

public interface IBinaryFileTransferService

{

    [OperationContract]

    byte[] GetFile(string strPath);

}

Listing 1. The BinaryFileTransferService service contract.

Afterwards, you need to create the service which implements the interface as shown in Listing 2.

public class BinaryFileTransferService : IBinaryFileTransferService

{

    public byte[] GetFile(string strPath)

    {

        return File.ReadAllBytes(strPath);

    }
}

Listing 2. The BinaryFileTransferService service implementation.

Now, we have the service host code generated by Visual Studio.NET. Listing 3.

internal class BinaryFileTransferServiceHost

{

    internal static ServiceHost myServiceHost = null;

 

    internal static void StartService()

    {

        // Consider putting the baseAddress in the configuration system

        // and getting it here with AppSettings

        Uri baseAddress = new Uri("http://localhost:8080/WCF_MTOM_Server/BinaryFileTransferService");

 

        // Instantiate new ServiceHost

        myServiceHost = new ServiceHost(typeof(BinaryFileTransferService), baseAddress);

 

        myServiceHost.Open();

    }

 

    internal static void StopService()

    {

        // Call StopService from your shutdown logic (i.e. dispose method)

        if (myServiceHost.State != CommunicationState.Closed)

            myServiceHost.Close();

    }
}


Listing 3. The Service Host instantiation.


In the application configuration file, we need to set the MTOM Encoding Binding element as part of our customized binding highlighted in yellow as show in Listing 4.

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

          <system.serviceModel>

        <services>

          <!-- Before deployment, you should remove the returnFaults behavior configuration to avoid disclosing information in exception messages -->

          <service name="WCF_MTOM_Server.BinaryFileTransferService" behaviorConfiguration="BinaryFileTransferServiceBeh">

            <endpoint contract="WCF_MTOM_Server.IBinaryFileTransferService" binding="customBinding" bindingConfiguration="MTOMCustomBinding" />

          </service>

        </services>

                   <bindings>

                             <customBinding>

                                      <binding name="MTOMCustomBinding">

                                                <mtomMessageEncoding messageVersion="Soap12"/>

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

                                                                                allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="true" keepAliveEnabled="true"

                                                                                maxBufferSize="65536" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"/>

                                      </binding>                       

                             </customBinding>                         

                   </bindings>

        <behaviors>

          <serviceBehaviors>

            <behavior name="BinaryFileTransferServiceBeh" >

              <serviceDebug includeExceptionDetailInFaults="true" />

                               <serviceMetadata httpGetEnabled="true" />

            </behavior>

           </serviceBehaviors>

        </behaviors>

     </system.serviceModel>

</configuration>


Listing 4. The configuration file.


Implementing the client in Oracle.


The first step is to create a service proxy through the Web Service Proxy Wizard in JDeveloper. In order to configure MTOM in the client generated by the Wizard, you need to set the property MTOM_SUPPORT to true in the Web proxy or in the configuration file as illustrated in Listing 5 (highlighted in yellow).

public static void main(String[] args)

{

    try

    {

        mtom_client.proxy.CustomBinding_IBinaryFileTransferServiceClient objProxyFactory = new mtom_client.proxy.CustomBinding_IBinaryFileTransferServiceClient();

       

        IBinaryFileTransferService objProxy = objProxyFactory.getPort();

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

        byte[] barrFile = objProxy.getFile("C:\\temp\\Communication\\In\\instal.iso");

        int nLength = barrFile.length;

        System.out.println("Length in bytes is "+nLength);      

    } catch (Exception ex)

    {

        ex.printStackTrace();

    }

}

Listing 5. Invocation to the service proxy.

 

Conclusion


This article has shown the implementation techniques to send binary data between applications running in different platforms (Microsoft.NET and Oracle AS) using standard protocols.

Login to add your contents and source code to this article
share this article :
post comment
 

John, I implemented interop between WCF and Oracle a while back, following the steps on this blog. The webservice is on a standalone OC4J server and WCF is the client. Evrything was working fine till we updated .Net Framework 3.0 from SP1 to SP2. The error we are getting is: Error creating a reader for the MTOM message. Inner exception is: Invalid MIME content-type header encountered on read. The MTOM content type looks like as below: Content-Type: application/xop+xml;charset=UTF-8;type="application/soap+xml;action=\"\";charset=UTF-8" I know axis folks had the same issue where WCF doesn't recognise the optional "action" parameter and the axis2 code was changed. Have you seen the same issues with oracle webservices and if they is a way to prevent this parse error in WCF. Any help is appreciated. Thanks, Jai

Posted by jaidude123 Mar 19, 2009
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor