2

This is about my solution to that question

It is been a long time since my last c# coding, and it is my first time to write a Web Service...

Previous Question:

I need to use a DLL on an Ubuntu with Python. Final solution is using a web service for that propose...

My problem is, the API is used for a kind of payment. There are three basic function of the DLL to be used in the webservice... First one is used for connection to the server, second one is asking available payments, third one is selecting one and making the payment...

Since my system is using Python, I wish to keep the logic that selects the payment method on python, not on the web service.

And my problem is, when I make a connection, webservice must create a connection object, and do the following two steps using that connection. That it may dispose that connection object and create a new one for the next connection and payment.

So, my Python code will do something like that...

  1. Use web service and create a connection
  2. Get a list of available payments from web service (these two functions can be used as a single function in the web service)
  3. Do some calculation and select the proper payment in python...
  4. Send payment method info to web service...

All these steps must be done with the connection object from the first step. As I said before, I do not have much knowledge about web services and using them on python... So I'm confused whether I may use the same connection object for steps 2 and 4. If I create the connection object as a global in my web service on the connection step, then my following function calls use that object? In OOP that's the way it must be, but I can not be sure if it will be same in web services?

Some code snippet :

namespace paymentType{
  public class x : System.Web.Services.WebService{

  ConnectionObj conn;
  ConnResult result;

  [WebMethod]
  public void ConnectToServer(String deviceId){
  conn = new ConnectionObj();
  result = baglanti.Connect(deviceId);
  }

  [WebMethod]
  public List<int> GetCompanyList(){
  List<int> kurumlar = new List<int>();
  if (sonuc.CRCStatus){
  if (baglanti.CompanyList != null) { blah blah blah...}

Since conn is a global, can i set it in the function call ConnectToServer and use the baglanti object for the other functions...

UPDATE: Let me try to get it more clear...

When I connect to remote server (via function in the DLL), remote server accepts my connection and give me a somewhat unique id for that connection. Then I ask for available payments for a customer. Server sends all available ones with a transaction id belong to that transaction. And in the final step, I use the transaction id that I want for doing the payment. Problem is, each transaction id is usable within the connection that it was created. So, I must request for transaction id and confirm the one I want in the same connection...

But as far as I see, best solution is using a single function call and do all the job on the web service since API provider considers removing the connection-transactionId lock might cause some security vulnerabilities...

But on the other hand, I do not want to handle it on the web service...

One more question... On the connection step, creating the connection and using set/get functions or returning the connection object and pass it back to the web service for each following step might work?

Community
  • 1
  • 1
Mp0int
  • 18,172
  • 15
  • 83
  • 114

1 Answers1

1

If you're communicating using a web service, it should preferrably be stateless – that is, you should always send any context information the service implementation needs in the request. While technologies that let you implement stateful web services exist, they'd likely make things more complicated, not less.

I'm not clear from your description on why you need the connection object to be created in Step 1, or why you can't just create a different connection object for steps 2 and 4 – which is how I'd implement this.

millimoose
  • 39,073
  • 9
  • 82
  • 134