C# client - php web server - couchbase db - how to pass data between them? [closed]

只谈情不闲聊 提交于 2020-01-07 08:00:22

问题


I am trying to understand the basic flow of a system consisting of:

  1. C# client/program/app which will query the PHP server.
  2. PHP server.
  3. Couchbase server running on Linux.

On the client side I have some classes, class MyClass {int,string,list etc}.

Based on other questions and answers, the flow should look like this:

C# client class->serialize to JSON-> post as string to PHP page-> (on PHP page) deserialize JSON string to PHP class ->posting to Couchbase -> getting result -> serialize to JSON->post as JSON string and return to the C# client -> etc

  1. Is that correct? Any suggestions?
  2. What are the best tools/packages, easiest way to serialize from JSON and to JSON in PHP?

Thanks for your help!


回答1:


Couchbase 2.0 is a database that allows you to store document directly. As soon as you have the JSON string you can store it into Couchbase using the PHP Client SDK.

That said, if you have a PHP object and you can use the json_encode()/json_decode() functions that are available in PHP.

You can take a look the the Getting Started and Tutorial from Couchbase: - http://www.couchbase.com/docs/couchbase-sdk-php-1.1/tutorial.html

Also you can look at this interested library that allows you to develop with PHP and Couchbase easily: - https://github.com/Basement/Basement You can look to use it, or look to see how it uses PHP and JSON.




回答2:


I wouldn't use XML. XML still has it's uses but for this kind of setup the industry is making a shift towards JSON. The C# client will use some kind of JSON serialization method on the data you wish to send to the PHP service. The PHP app can then deserialize it and perform the appropriate actions. From there you write to your database like you would normally.

.Net comes with the JavascriptSerializer which works fine for basic situations but you should probably look into using JSON.Net as it provides a lot more flexibility.

PHP also has some built in JSON serialization stuff but I haven't used it so I can't speak to how well it works. However this article is linked to by JSON.org so it should give you a pretty good idea: http://gggeek.altervista.org/sw/article_20061113.html



来源:https://stackoverflow.com/questions/14531719/c-sharp-client-php-web-server-couchbase-db-how-to-pass-data-between-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!