public override void Test(UpdateDelegate action) { string appSetting = ConfigurationManager.AppSettings["CertPath"]; if (string.IsNullOrEmpty(appSetting)) { throw new Exception("授权文件路径为空,需要进行设置!设置位置: Web.Config->appSettings->CertPath"); } string certPath = appSetting + "\\client.p12"; if (!File.Exists(certPath)) { throw new Exception("授权文件不存在, 请确认文件夹路径是否正确!" + certPath); } string password = "******"; string currentPath = Directory.GetCurrentDirectory(); TTransport transport = new TTLSSocket(m_Ip, 7912, new X509Certificate2(certPath, password), RemoteCertificateCallback); TProtocol protocol = new TBinaryProtocol(transport); PrintServices.Client client = new PrintServices.Client(protocol); m_StrTransport = "TTLSSocket"; m_StrProtocol = "TBinaryProtocol"; HandleAdd(transport, client, action); }
public override void Test(UpdateDelegate action) { TTransport transport = new TSocket(m_Ip, 7911); TProtocol protocol = new TBinaryProtocol(transport, false, false); PrintServices.Client client = new PrintServices.Client(protocol); m_StrTransport = "TSocket"; m_StrProtocol = "TBinaryProtocol"; HandleAdd(transport, client, action); }
public override void Test(UpdateDelegate action) { TTransport transport = new TSocket(m_Ip, 7915); TProtocol protocol = new TCompactProtocol(transport); PrintServices.Client client = new PrintServices.Client(protocol); m_StrTransport = "TSocket"; m_StrProtocol = "TProtocolCompact"; HandleAdd(transport, client, action); }
public override void Test(UpdateDelegate action) { string myUri = @"http://" + m_Ip + @":7913"; TTransport transport = new THttpClient(new Uri(myUri)); TProtocol protocol = new TJSONProtocol(transport); PrintServices.Client client = new PrintServices.Client(protocol); m_StrTransport = "THttpClient"; m_StrProtocol = "TBinaryProtocol"; HandleAdd(transport, client, action); }
public void HandleAdd(TTransport transport, PrintServices.Client client, UpdateDelegate action) { try { transport.Open(); testAdd(client, action); } catch (System.Exception) { throw new Exception("无法连接到服务器[ip和port是否设置正确]"); } finally { transport.Close(); } }
public override void Test(UpdateDelegate action) { string pipeName = "pipe123"; TTransport transport = new TNamedPipeClientTransport(pipeName); TProtocol protocol = new TBinaryProtocol(transport); PrintServices.Client client = new PrintServices.Client(protocol); m_StrTransport = "TNamedPipe"; m_StrProtocol = "TBinaryProtocol"; if (!transport.IsOpen) { transport.Open(); } testAdd(client, action); transport.Close(); }
public void testAdd(PrintServices.Client client, UpdateDelegate action) { int x = 1; int y = 2; int sum = client.add(x, y); m_result = "x=" + x + "," + "y=" + y + "," + "Sum=" + sum; string str = m_StrTransport + "\n" + m_StrProtocol + "\n" + m_result + "\n"; action(str); if (sum != x + y) { throw new TestFailedException("testAdd Fail!"); } return; }