В настоящее время я храню информацию о соединении с C# mysql внутри самого файла класса, который не кажется таким умным, поскольку конечные пользователи могут просто использовать отражатель, например NET Reflector, для отладки исходного кода в дело не обструкционировано.Использование PHP webservice в приложении winforms
Теперь пользователь в stackoverflow рекомендует создать веб-службу, которая будет манипулировать базой данных. Программное обеспечение, которое конечный пользователь будет использовать, затем просто аутентифицируется с помощью веб-службы, используя учетные данные пользователя, а затем использует это для доступа к ресурсам.
Теперь у меня есть следующая проблема: Мой сервер работает на linux ubuntu и уже хранит веб-сайт, созданный с помощью функции plesk.
Я знаю, что я мог бы использовать http://www.mono-project.com/ для размещения веб-сервиса на linux. Но я никогда не делал этого, так как я всегда использовал PHP, чтобы делать такие вещи, и я немного смущен тем, как загрузить веб-сервис C# в установленную моно версию на ssh-сервере.
Могу ли я использовать что-то вроде следующего PHP-кода в качестве веб-службы C# в моем приложении winforms?
код PHP:
<?php
class webService extends database
{
// Web service constructor
public function __construct($username, $password, $uniqueId, $versionId)
{
$this->username = $username;
$this->password = $password;
$this->salt = 'xxx';
$this->hash = 'xxx';
$this->uniqueId = $uniqueid;
$this->versionId = $versionId;
}
// Web service functions to check database values
// Web service user account check function
private function userCheck()
{
$this->connect();
$userCheck = $this->execute_query("SELECT username, password FROM Users WHERE username = '" . $this->username . "' AND password = '" . $this->hash . "'");
if($userCheck && mysqli_num_rows($userCheck) > 0)
{
return 'true';
}
else
{
return 'false';
}
}
// Web service unique id check function
private function uniqueCheck()
{
$this->connect();
$uniqueCheck = $this->execute_query("SELECT username, uniqueid FROM Users WHERE username = '" . $this->username . "' AND uniqueid = '" . $this->uniqueId . "'");
if($uniqueCheck && mysqli_num_rows($uniqueCheck) > 0)
{
return 'true';
}
else
{
return 'false';
}
}
// Web service first run check function
private function firstRunCheck()
{
$this->connect();
$firstRunCheck = $this->execute_query("SELECT username, firstrun FROM Users WHERE username = '" . $this->username . "' AND firstrun = '0'");
if($firstRunCheck && mysqli_num_rows($firstRunCheck) > 0)
{
return 'true';
}
else
{
return 'false';
}
}
// Web service user disabled check function
private function disabledUserCheck()
{
$this->connect();
$disabledUserCheck = $this->execute_query("SELECT disabled FROM Users WHERE username = '" . $this->username . "' AND disabled = '1'");
if($disabledUserCheck && mysqli_num_rows($disabledUserCheck) > 0)
{
return 'true';
}
else
{
return 'false';
}
}
// Web service update required check function
private function updateRequiredCheck()
{
$this->connect();
$updateRequiredCheck = $this->execute_query("SELECT requiredupdate FROM requiredupdate WHERE version = '" . $this->versionId . "' AND requiredupdate = 1");
if($updateRequiredCheck && mysqli_num_rows($updateRequiredCheck) > 0)
{
return 'true';
}
else
{
return 'false';
}
}
// Web service premium check function
private function userPremiumCheck()
{
$this->connect();
$userPremiumCheck = $this->execute_query("SELECT premium FROM Users WHERE username = '" . $this->username . "' AND premium = 1");
if($userPremiumCheck && mysqli_num_rows($userPremiumCheck) > 0)
{
return 'true';
}
else
{
return 'false';
}
}
// Web service functions to update database values
// Web service update first run parameters function
private function firstRunUpdate()
{
$firstRunCheck = $this->firstRunCheck();
if($firstRunCheck == 'true')
{
$this->connect();
$this->execute_query("UPDATE Users SET uniqueid = '" . $this->uniqueId . "', firstrun = '1' WHERE username = '" . $this->username . "'");
return 'true';
}
else
{
return 'false';
}
}
function to_xml(SimpleXMLElement $object, array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
$object->addChild($key, $value);
}
}
}
// Web service handler function
public function webService()
{
$userCheck = $this->userCheck();
if($userCheck == 'true')
{
$userArray = array (
'username' => $this->username,
'authentificated' => $this->userCheck(),
'firstRun' => $this->firstRunCheck(),
'firstRunUpdated' => $this->firstRunUpdate(),
'uniqueIdCheck' => $this->uniqueCheck(),
'Premium' => $this->userPremiumCheck(),
'Disabled' => $this->disabledUserCheck(),
'updateRequired' => $this->updateRequiredCheck()
);
}
else
{
$userArray = array (
'username' => $this->username,
'userCheck' => $this->userCheck()
);
}
echo str_replace("\/", "/", json_encode($userArray, JSON_PRETTY_PRINT));
}
}
?>
Или как является PHP создан Web-сервис, который мог привыкнуть в моем приложении?
Текущий ответ от PHP скрипта будет выглядеть следующим образом:
{ "username": "dane", "authentificated": "true", "firstRun": "false", "firstRunUpdated": "false", "uniqueIdCheck": "true", "Premium": "true", "Disabled": "false", "updateRequired": "false" }
Если служба может принимать HTTP-запросы и возвращать ответы HTTP, то да, вы можете вызвать ее из приложения winforms. – Crowcoder