how to write service to contract