opcenter8跨平台开发

是从camstar7以后的版本更改名称为opcenter ,调用和设计的方式和7版本基本一样,重点说api的调用方式

opcenter之前的版本调用api直接在xml中传入用户的密码就可以了,opcenter更改为先登陆获取sessionid,然后再提交xml,

 public ICsiSession CreateSession(string userName, string password, string sessionName)
        {
            lock (this)
            {
                if (this.FindSession(sessionName) != null)
                    throw new CsiClientException(3014680L, this.GetType().FullName + ".createSession()");
                ICsiSession csiSession = (ICsiSession)new CsiSession(userName, password, (ICsiConnection)this);
                csiSession.Host = this.mHost;
                csiSession.Port = this.mPort;
                string license = CsiSessionManager.AddOrGetLicense(this.mHost, this.mPort, userName, password);
                csiSession.SessionId = !string.IsNullOrEmpty(license) ? license : throw new CsiClientException(3014683L, this.GetType().FullName + ".createSession()");
                this.mSessions[(object)sessionName] = (object)csiSession;
                return csiSession;
            }
        }

sessionid的获取方式为调用camstar security services的WCF服务,官方的insitexmlclient经过反编译后可以看到

private static AuthenticationServiceClient AuthenticationClient(
      string host)
    {
      bool flag1 = false;
      if (string.IsNullOrEmpty(host))
        host = "localhost";
      else
        flag1 = true;
      UriBuilder uriBuilder = new UriBuilder(csiWCFUtilities.GetValueFromCamstarRegistry("Camstar InSite Common", "AuthenticationServiceUrl", string.Format("https://{0}/camstarsecurityservices/authenticationservice.svc", (object) host)));
      if (flag1)
        uriBuilder.Host = host;
      Uri uri = uriBuilder.Uri;
      bool flag2 = "https".Equals(uri.Scheme, StringComparison.OrdinalIgnoreCase);
      EndpointAddress remoteAddress = new EndpointAddress(uri, Array.Empty<AddressHeader>());
      return new AuthenticationServiceClient(flag2 ? (Binding) new BasicHttpsBinding() : (Binding) new BasicHttpBinding(), remoteAddress);
    }

    public static string LogIn(
      string userName,
      string userPassword,
      out string sessionId,
      string host)
    {
      sessionId = string.Empty;
      string str = string.Empty;
      AuthenticationServiceClient authenticationServiceClient = csiWCFUtilities.AuthenticationClient(host);
      try
      {
        ResultStatus resultStatus = authenticationServiceClient.LoginFromXMLClient(userName, userPassword, ref sessionId);
        if (resultStatus != null && !resultStatus.IsSuccess)
          str = resultStatus.Message;
      }
      catch (Exception ex)
      {
        str = ex.Message;
      }
      finally
      {
        authenticationServiceClient.Close();
      }
      return str;
    }

除了以上差异,opcenter还添加的SSL的支持,这样如果内网中用https的话用官方的insitexmlclient调用会报SSL错误,跨平台的insitexmlclient为了做到轻量把其中的几个整合到一起,删除了WCF依赖和其他windows平台下的依赖,调用https错误等问题

代码库:https://github.com/307209239/InSiteXMLClient_v8

nuget包:

 使用的方法跟7版本一致,详细请参考我之前的文章

camstar跨平台开发 - 悳鎭 - 博客园 (cnblogs.com)

原文地址:https://www.cnblogs.com/lidezhen/p/14824147.html