gpt4 book ai didi

php - 使用 PHP/MYSQL Web 服务 (WSDL) 的 ASP.NET/C# 客户端

转载 作者:可可西里 更新时间:2023-11-01 06:51:34 25 4
gpt4 key购买 nike

我正在尝试访问网络服务(下面的两个文件)。客户使用 ASP.NET/C# 作为他们的网络架构。我可以添加 Web 引用,但不知何故我无法为 wsdl 文件生成代理类。目的是使用 server.php 文件中的函数,以便我可以使用 xmlstring 在 ASP.NET 网站上显示数据。任何帮助将不胜感激。非常感谢


server.php 文件。该文件有一个 php 函数,该函数从 mysql 数据库中提取数据,该函数将数据作为 XML 字符串返回。

<?php
//WEB SERVICE FUNCTION TO EXTRACT DATA FROM CLIENT B INTO XML FORMAT
function getXML()
{
//CONNECT TO THE DATABASE SERVER
$dbserverIP = "xxxxxxx";
$dbusername = "xxxxxxx";
$dbpassword = "xxxxxxx";
$dbconnection = mysql_connect($dbserverIP,$dbusername,$dbpassword)
or die ("The connection to the database server failed.");

//CONNECT TO THE DATABASE
$dbname = "xxxxxxxx";
$dbselectok = mysql_select_db($dbname,$dbconnection)
or die ("The connection to the database failed.");

//QUERY THE DATABASE
$sqlquery = "SELECT * FROM videogames";
$sqlresult = mysql_query($sqlquery,$dbconnection)
or die ("Error in executing the SQL statement");

//CREATE XML STRING
$xmlstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
$xmlstring.= "<videogames>";

while ($row = mysql_fetch_array($sqlresult))
{
$xmlstring .= "\t<game>\r\n";
$xmlstring .= "\t\t<gametitle>" .$row["gametitle"]. "</gametitle>\r\n";
$xmlstring .= "\t\t<genre>" .$row["genre"]. "</genre>\r\n";
$xmlstring .= "\t\t<year>" .$row["year"]. "</year>\r\n";
$xmlstring .= "\t\t<platform>" .$row["platform"]. "</platform>\r\n";
$xmlstring .= "\t\t<agerating>" .$row["agerating"]. "</agerating>\r\n";
$xmlstring .= "\t\t<price>" .$row["price"]. "</price>\r\n";
$xmlstring .= "\t</game>\r\n";
}

$xmlstring.= "</videogames>";

//WRITE XML STRING TO EXTERNAL FILE
$filename = "videogames.xml";
$fileaccessmode = "w";
$fptr = fopen($filename,$fileaccessmode);
fwrite($fptr,$xmlstring);
fclose($fptr);

//FREE UP MEMORY
mysql_free_result($sqlresult);
mysql_close($dbconnection);

return $xmlstring;

}

//CODE TO DISABLE THE WSDLE CACHE
ini_set("soap.wsdl_cache_enabled","0");

//DEFINE SOAP SERVER INSTANCE AND RELATED WSDL FILE
//THE service.wsdl FILE IS IN THE SAME FOLDER AS THIS server.php FILE
$server = new SoapServer("service.wsdl");

//ADD FUNCTION TO THE SERVER INSTANCE
$server->addFunction("getXML");

//ACTIVATE THE SOAP HANDLER
$server->handle();

?>

这是链接到 server.php 文件的 WSDL 文件。

<?xml version ='1.0' encoding ='UTF-8' ?>

<!-- ====================== DEFINITIONS ====================== -->

<definitions name="MyWebService"
targetNamespace="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/service.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/service.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!-- ====================== TYPES ============================ -->
<!-- No need for type definitions as only xsd built-in ======= -->
<!-- data types are used -->
<!-- ========================================================= -->

<!-- ====================== MESSAGE ========================== -->

<message name="getXML_Request">
<part name="input" />
</message>

<message name="getXML_Response">
<part name="xmlString" type="xsd:string"/>
</message>

<!-- ====================== PORT TYPE ============================ -->

<portType name="myWebService_PortType">

<operation name="getXML">
<input message="tns:getXML_Request"/>
<output message="tns:getXML_Response"/>
</operation>

</portType>

<!-- ======================= BINDING ============================= -->

<binding name="myWebService_Binding" type="tns:myWebService_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="getXML">
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>

</binding>

<!-- ======================= SERVICE ============================= -->

<service name="myWebService_Service">
<port name="myWebService_Port" binding="tns:myWebService_Binding">
<soap:address location="http://cet-apache-04.cet.bolton.ac.uk/student/mib1bee/CST3017/assignment/scenario1/server.php"/>
</port>
</service>

</definitions>

最佳答案

你只需要通读这篇文章,你就会对你的答案有一个清晰的了解

转到以下链接:

php web service to dot net

关于php - 使用 PHP/MYSQL Web 服务 (WSDL) 的 ASP.NET/C# 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10558414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com