Ask a questionAsk a question
 

Proposed AnswerWCF with Oracle.DataAccess

  • Tuesday, November 03, 2009 6:48 PMFilip Mateasko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,
    I have Win7 x64. I'm trying to develop WCF service used to write logs into Oracle database. I'm using following function in the service.
    ´

    Imports System.Data.OleDb

    Imports Oracle.DataAccess.Client

     

    Public Class Service1

        Implements IService1

     

     

     

        Public Function WriteError(ByVal msg As String) As String Implements IService1.WriteError

            Dim myConn As OracleConnection = Nothing

            Dim result As String

            Try

                myConn = New OracleConnection("Password=aaa;Persist Security Info=True;User ID=fim;Data Source=IsemOracle") 'My.Settings.dbLogConnectionString)

                myConn.Open()

                Dim myCommand = New OracleCommand("Insert into LOGGER (TYPE,LOGTEXT) values (1,'" & msg & "')", myConn)

                Dim ra As Integer = myCommand.ExecuteNonQuery()

                If ra = 1 Then

                    result = "OK"

                Else

                    result = "The record not written from not known reason. Check the DBLogger, WriteLog function please."

                End If

            Catch ex As Exception

                result = ex.ToString

            Finally

                If Not myConn Is Nothing Then myConn.Close()

            End Try

     

            Return result

        End Function

    End Class

     

     

    If I run the same code in the console app, i works perfectly, however if I run it in WCF, it throws following exception



    Could not load file or assembly 'Oracle.DataAccess, Version=2.111.7.20, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at IService1.WriteError(String msg)
       at Service1Client.WriteError(String msg)


    I tried also to use

    Data.OleDb.OleDbConnection("Provider=OraOLEDB.Oracle.1;Password=aaa;Persist Security Info=True;User ID=fim;Data Source=IsemOracle")


    but then I received error that OraOLEDB.Oracle.1 is not registered on the local machine. But if I run the same code from console, it runs perfectly.

    Any idea ?

    Thanks

    Filip

     

All Replies

  • Wednesday, November 04, 2009 1:04 AMHaripraghash Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I am using the same component in my WCF project as well. The component you use seems to be very old. The latest ODAC(Oracle data access components) can be found here.

    http://www.oracle.com/technology/software/tech/windows/odpnet/index.html

    How did you add oracle.dataaccess.dll to your wcf project?from GAC or from directly the installation folder?Also can you cehck your eventlogs for any exception deails
    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
  • Wednesday, November 04, 2009 7:59 AMFilip Mateasko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    the ODAC is the last actual one, I downloaded and installed it only 2 days ago.
    I tried to reference the library from GAC and also from installation folder (wnich is not on system partition C, because of lack of space there, however, I don't think it could be problem, do you ?) I tried to set copy Local to true or false, the same result.
    For compilation there is set: Target CPU - Any CPU, Target framework 3.5. To test the service I'm using WcfTestClient.exe. If I set the Taget CPU to X86, then I receive error:

    System.BadImageFormatException: Could not load file or assembly 'file:///D:\work\3253_ISEM\App\TESTY\WcfServiceLibraryTest2\bin\Debug\WcfServiceLibraryTest2.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    File name: 'file:///D:\work\3253_ISEM\App\TESTY\WcfServiceLibraryTest2\bin\Debug\WcfServiceLibraryTest2.dll'
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
       at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)

    In event log, I don't know where to look - if you mean via Windows Event Viewer - or what have you meant ?

    Thanks

    Filip
  • Wednesday, November 04, 2009 2:57 PMFilip Mateasko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    So finally I found the solution :-)

    At this moment I've tested it only with OraOLEDB.Oracle.1, but I hope it will work also with Oracle.DataAccess. The problem was, that I compiled the WCF for Any CPU, but the oracle libraries are 32bit. When I tried to set the project to compile only for x86 and tried to use built in WcfTestClient.exe, I got above mentioned error. I thought the problem is in Oracle libraries, however it's in WcfTestHost and solution is here http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/2e29a4aa-e587-43ef-bf50-329b7cd3eefb

    Now everithing works well, uff.

    F. 
    • Marked As Answer byFilip Mateasko Wednesday, November 04, 2009 2:57 PM
    • Unmarked As Answer byFilip Mateasko Thursday, November 19, 2009 11:27 AM
    • Proposed As Answer byNEfimtseva Friday, November 27, 2009 2:51 PM
    •  
  • Wednesday, November 25, 2009 10:15 AMYunuen79 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Man, you are my hero!!!. I spent a few hours trying to make this work. The platform target was the problem.

    Thanks a lot.