Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Open part Issue during NX Remoting Server/Client connection

Hi! I am trying to develop a .NET application that enables the calling of a NXopen method (written in VB) by means of a Server/Client connection. I looked into the remoting example that is available in the NX directory (and into the .NET translation available at https://community.plm.automation.siemens.com/t5/NX-Programming-Customization/Creating-NX-Open-applic...) and this is what i came up with:

 

Option Explicit On
Option Strict Off

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports NXOpen
Imports System.Runtime.Remoting.Channels.Http
Imports System.Threading
Imports System.Runtime.Remoting.Lifetime
' interface of remote object
Public Interface IRemoteObject
        Sub SomeJob()
    End Interface
' some const
Public Module SomeConst
    Public Const Port As Integer = 4567
    Public Const DefaultURIString As String = "http://localhost:4567/RO"
End Module

' MyProgram class is remotable
Public Class MyProgram
    Inherits MarshalByRefObject
    Implements IRemoteObject

    Dim theSession As NXOpen.Session
    Dim theUfSession As UF.UFSession

    Public Sub SomeJob() Implements IRemoteObject.SomeJob

        Dim path_to_an_existing_prt_file As String = "some_file.prt"

        theSession = NXOpen.Session.GetSession()
        theUfSession = UF.UFSession.GetUFSession()

        Dim basePart1 As NXOpen.BasePart
        Dim partLoadStatus1 As NXOpen.PartLoadStatus
        ' the next line raises an 11 exception "internal error: memory access violation" when called from remote by Client module
        basePart1 = theSession.Parts.OpenDisplay(path_to_an_existing_prt_file, partLoadStatus1)

        Dim workPart As NXOpen.Part = theSession.Parts.Work

        Dim displayPart As NXOpen.Part = theSession.Parts.Display

        partLoadStatus1.Dispose()

        '----------------------- omitting the rest of the job's code  ------------------------------------------------------

    End Sub

End Class

Public Module Server

    Public Function Startup(ByVal args As String()) As Integer
        Start()
        Return 0
    End Function
    Public Sub Start()
        Dim serverThread As Thread = New Thread(New ThreadStart(AddressOf Run))
        serverThread.Start()
    End Sub

    Public Sub Run()

        LifetimeServices.LeaseTime = System.TimeSpan.FromDays(10000)

        Dim provider As SoapServerFormatterSinkProvider = New SoapServerFormatterSinkProvider()
        provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full

        ' Create the IDictionary to set the port on the channel instance.

        Dim props As New Hashtable
        'IDictionary(props = New Hashtable())
        Dim lnkprov As System.Runtime.Remoting.Channels.IServerChannelSinkProvider

        props.Add("port", SomeConst.Port)
        ' Create a new http channel with the given provider and properties
        ChannelServices.RegisterChannel(New HttpChannel(props, lnkprov, provider), False)
        ' Create remote object
        Dim RO As MyProgram = New MyProgram()
        ' marshaling
        RemotingServices.Marshal(RO, "RO")

        While True
            Thread.Sleep(1000)
        End While

    End Sub

End Module

Public Module Client
    Dim ensureSecurityflag As Boolean = False
    Sub Main()
        Dim channel As HttpClientChannel = New HttpClientChannel()
        ChannelServices.RegisterChannel(channel, ensureSecurityflag)
        Dim OB As Object = Activator.GetObject(GetType(IRemoteObject), SomeConst.DefaultURIString)
        Dim RO As IRemoteObject = CType(OB, IRemoteObject)
        ' Next line fails and generates exception
        RO.SomeJob()
        ChannelServices.UnregisterChannel(channel)
    End Sub

End Module

 

I know that the "SomeJob" method works correctly, because if launched locally it runs smoothly, but I can't manage to run it with the remoting connection (line 100), whenever i call the client module by the windows prompt.

In this case, as it's written in the code comments, I get an error on line __: "error 11 - internal error memory access violation". The connection and the call to the server made by the client module seem to work fine: while debugging (during remote connection), the execution enters in the "SomeJob" method, showing that the call to the server is successfully, but it crashes on the "open part" command. 

 

 

Are there any NX open functions/methods not available during the remoting session? In my application I need to launch automatically a dll (hence the need for the remoting session) that has access to display functions, such as the deviation gauge tool.

 

 Help!

 

 

 

7 REPLIES

Re: Open part Issue during NX Remoting Server/Client connection

Dim path_to_an_existing_prt_file As String = "some_file.prt"

Try assigning the full path, rather than just the part name.

 

NX will look only in the current directory when you specify it that way, and the current directory may not be what you are expecting.

 

Re: Open part Issue during NX Remoting Server/Client connection

Of course, that is just an example for this forum. I wrote the full path in my application. (and as I said, the "somejob" works perfectly if launched locally)

Re: Open part Issue during NX Remoting Server/Client connection

 

What version of NX are you using?  I would like to run a test.  Thanks!

Re: Open part Issue during NX Remoting Server/Client connection

10.0 and thanks for your help!
Solution
Solution
Accepted by topic author FrancescoB
‎06-09-2016 08:11 AM

Re: Open part Issue during NX Remoting Server/Client connection

 

The attached worked fine for me in NX10 - the base release.  Of course you will need to change the filespec in the client program.

 

 

Re: Open part Issue during NX Remoting Server/Client connection

So basically you are able to open a part without problems right?

Re: Open part Issue during NX Remoting Server/Client connection

I'll try as soon as I will be back to work