我是Web服务的新手,我有一个尚未解决的问题。
所以这是我的wsdl
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name="Biodata"
targetNamespace="urn:TestNamespace"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="TestNamespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'>
<message name='insertReplyRequest'>
<part name='reply' element="Biodata"/>
</message>
<portType name='BiodataPortType'>
<operation name='insertReply'>
<input message='tns:insertReplyRequest'>
</operation>
</portType>
<binding name='BiodataBinding' type='tns:BiodataPortType'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='insertReply'>
<soap:operation soapAction='insertReply'/>
<input>
<soap:body use='encoded' namespace='urn:examples:biodata'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
</operation>
</binding>
<service name='BiodataService'>
<port name='BiodataPort' binding='tns:BiodataBinding'>
<soap:address location='http://localhost/Kevin/FirstWebService/Asynchronous/server.php'/>
</port>
</service>
</definitions>
这是文件reply.php
<?php
$reply = $_POST["reply"];
$post_id = $_POST["post_id"];
$client = new SoapClient("http://localhost/Kevin/FirstWebService/Asynchronous/biodata.wsdl");
$return = $client->insertReply($reply, $post_id);
header("Location: http://localhost/Kevin/FirstWebService/Asynchronous/reply.html");
die();
?>
reply.html是:
<!DOCTYPE html>
<html>
<head>
<title>Reply</title>
</head>
<form action="reply.php" method=POST>
REPLY:<br>
<input type="text" name="reply">
<br>
POST ID<br>
<input type="text" name="post_id">
<br>
<input type="submit" value="Submit">
</form>
</html>
功能如下:
<?php
function insertReply($reply, $post_id){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "structure2";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO reply (reply, post_id) VALUES ('$reply', '$post_id')";
$result = $conn->query($sql);
} ?>
和服务器:
<?php
require 'biodata_functions.php';
//require 'SoapFault.php';
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("http://localhost/Kevin/FirstWebService/Asynchronous/biodata.wsdl");
/*$server->addFunction("getName");
*/
$server->addFunction("insertPost");
$server->addFunction("insertReply");
$server->handle();
?>
我的问题是,我无法同时使用$ reply插入$ post_id,每当我这样做时,它在sql表中都会以空白结束。
我甚至尝试将函数代码中的$ sql更改为:
$sql = "INSERT INTO reply (reply, post_id) VALUES ('$reply', '8')";
它在数据库中成功输入了8。
我的查询有问题吗?或者我的逻辑有什么问题?任何帮助将不胜感激,谢谢