public static void runHelloWorldExample() { Uri u = new Uri("http://localhost:9090"); TTransport transport = new THttpClient(u); TProtocol protocol = new TBinaryProtocol(transport); HelloWorld.Client client = new HelloWorld.Client(protocol); transport.Open(); client.ping(); Console.WriteLine("ping()"); string msg = client.sayHello(); Console.WriteLine(msg); msg = client.sayMsg(Constants.HELLO_IN_KOREAN); Console.WriteLine(msg); HelloStruct hellostruct = client.structTest(Constants.HELLO_IN_JAPANESE); Console.WriteLine(hellostruct.Id); transport.Close(); }
/// <summary> /// Thrift의 실제 Client instance를 반환하는 메서드. /// /// 현재는 Transport와 Protocol이 각각 THttpClient와 TBinarnyProtocol로 명시되어 있음. /// 향후 Connection pooling등이 필요하게 될지도 모름. /// </summary> /// <returns></returns> private Outbound_ItemService.Client GetClient() { TTransport trans = new THttpClient(new Uri(ServiceUrl)); try { trans.Open(); } catch (Exception ex) { throw new ThriftClientException("연결을 생성할 수 없습니다.\n" + ex.Message); } TProtocol proto = new TBinaryProtocol(trans); Outbound_ItemService.Client client = new Outbound_ItemService.Client(proto); return client; }