1. 程式人生 > >使用 utgard 讀取plc時 出現 org.jinterop.dcom.common.JIException: Access is denied. [0x80070005]

使用 utgard 讀取plc時 出現 org.jinterop.dcom.common.JIException: Access is denied. [0x80070005]

在使用utgard通過opcservice讀取plc資料時有些opcservice(kingIoservice) 會出現如下錯誤:

Caused by: org.jinterop.dcom.common.JIRuntimeException: Access is denied.  [0x80070005]
	at org.jinterop.dcom.core.JICallBuilder.readResult(JICallBuilder.java:1077)
	at org.jinterop.dcom.core.JICallBuilder.read(JICallBuilder.java:957)
	at ndr.NdrObject.decode(NdrObject.java:19)
	at rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:138)
	at rpc.Stub.call(Stub.java:112)
	at org.jinterop.dcom.core.JIComServer.call(JIComServer.java:870)
	... 6 common frames omitted

解決辦法如下:

修改utgard的原始碼 server.java

 原本的程式碼如下

 if (this.connectionInformation.getClsid() != null) {
                    this.session = JISession.createSession(this.connectionInformation.getDomain(), this.connectionInformation.getUser(), this.connectionInformation.getPassword());
                    this.session.setGlobalSocketTimeout(socketTimeout);
                    this.comServer = new JIComServer(JIClsid.valueOf(this.connectionInformation.getClsid()), this.connectionInformation.getHost(), this.session);
                } else {
                    if (this.connectionInformation.getProgId() == null) {
                        throw new IllegalArgumentException("Neither clsid nor progid is valid!");
                    }

                    this.session = JISession.createSession(this.connectionInformation.getDomain(), this.connectionInformation.getUser(), this.connectionInformation.getPassword());
                    this.session.setGlobalSocketTimeout(socketTimeout);
                    this.comServer = new JIComServer(JIProgId.valueOf(this.connectionInformation.getProgId()), this.connectionInformation.getHost(), this.session);
                }

修改是隻要加上

this.session.useSessionSecurity(true);

修改的程式碼如下

if ( this.connectionInformation.getClsid () != null )
            {
                this.session = JISession.createSession ( this.connectionInformation.getDomain (), this.connectionInformation.getUser (), this.connectionInformation.getPassword () );
                this.session.setGlobalSocketTimeout ( socketTimeout );
                this.session.useSessionSecurity(true);
                this.comServer = new JIComServer ( JIClsid.valueOf ( this.connectionInformation.getClsid () ), this.connectionInformation.getHost (), this.session );
            }
            else if ( this.connectionInformation.getProgId () != null )
            {
                this.session = JISession.createSession ( this.connectionInformation.getDomain (), this.connectionInformation.getUser (), this.connectionInformation.getPassword () );
                this.session.setGlobalSocketTimeout ( socketTimeout );
                this.session.useSessionSecurity(true);
                this.comServer = new JIComServer ( JIProgId.valueOf ( this.connectionInformation.getProgId () ), this.connectionInformation.getHost (), this.session );
            }