加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 我需要帮助创建.wsdl文件 – 需要多个函数!

发布时间:2021-08-28 03:43:29 所属栏目:大数据 来源: https://www.jb51.cc
导读:我正在尝试创建一个Web服务,为此我已经阅读了一个很棒的教程:web service tutorial.现在,一切正常,但是对于我正在开发的服务,我需要在.wsdl文件.我试图再添加一个函数,我不断收到错误消息.这就是我的.wsdl的样子: ?xml version ='1.0' encoding ='UTF-8' ?

我正在尝试创建一个Web服务,为此我已经阅读了一个很棒的教程:web service tutorial.现在,一切正常,但是对于我正在开发的服务,我需要在.wsdl文件.我试图再添加一个函数,我不断收到错误消息.这就是我的.wsdl的样子:

<?xml version ='1.0' encoding ='UTF-8' ?> 
<definitions name='Catalog' 
  targetNamespace='http://example.org/catalog' 
  xmlns:tns=' http://example.org/catalog ' 
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
  xmlns='http://schemas.xmlsoap.org/wsdl/'> 

<message name='getCatalogRequest'> 
  <part name='catalogId' type='xsd:string'/> 
</message> 
<message name='getCatalogResponse'> 
  <part name='Result' type='xsd:string'/> 
</message> 

<message name='getTestMessageRequest'> 
  <part name='testMessage' type='xsd:string'/> 
</message> 
<message name='getTestMessageResponse'> 
  <part name='resultTestMessage' type='xsd:string'/> 
</message> 


<portType name='CatalogPortType'> 
  <operation name='getCatalogEntry'> 
    <input message='tns:getCatalogRequest'/> 
    <output message='tns:getCatalogResponse'/> 
  </operation> 
  <operation name='getTestMessage'> 
    <input message='tns:getTestMessageRequest'/> 
    <output message='tns:getTestMessageResponse'/> 
  </operation> 
</portType> 



<binding name='CatalogBinding' type='tns:CatalogPortType'> 
  <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/> 

  <operation name='getCatalogEntry'> 
    <soap:operation soapAction='urn:localhost-catalog#getCatalogEntry'/> 
    <input> 
      <soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </input> 
    <output> 
      <soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </output> 
  </operation>

  <operation name='getTestMessage'> 
    <soap:operation soapAction='urn:localhost-catalog#getTestMessage'/> 
    <input> 
      <soap:body use='literal'/> 
    </input> 
    <output> 
      <soap:body use='literal'/> 
    </output> 
  </operation> 
</binding> 

<service name='CatalogService'> 
  <port name='CatalogPort' binding='CatalogBinding'> 
    <soap:address location='http://www.thevinylfactory.com.PHP5-8.dfw1-2.websitetestlink.com/ws/soap-server.PHP'/> 
  </port> 
</service>

</definitions>

我的soap-server.PHP

<?PHP
function getCatalogEntry($catalogId) { 
  if($catalogId=='catalog1')
          return "<HTML>
 <HEAD>
  <TITLE>Catalog</TITLE>
 </HEAD
 <BODY>
<p> </p>
 <table border>
<tr><th>CatalogId</th>
<th>Journal</th><th>Section
</th><th>Edition</th><th>
Title</th><th>Author</th>
</tr><tr><td>catalog1</td>
<td>IBM developerWorks</td><td>
XML</td><td>October 2005</td>
<td>JAXP validation</td>
<td>Brett McLaughlin</td></tr>
</table>
</BODY>
</HTML>";
  elseif ($catalogId='catalog2')
          return "<HTML>
 <HEAD>
  <TITLE>Catalog</TITLE>
 </HEAD
 <BODY>
<p> </p>
 <table border>

<tr><th>CatalogId</th><th>
Journal</th><th>Section</th>
<th>Edition</th><th>Title
</th><th>Author
</th></tr><tr><td>catalog1
</td><td>IBM developerWorks</td>
<td>XML</td><td>July 2006</td>
<td>The Java XPath API
</td><td>Elliotte Harold</td>
</tr>
</table>
</BODY>
</HTML>";
}

function getTestMessage($testMessage)
{
    return $testMessage."dsa";

}

ini_set("soap.wsdl_cache_enabled", "0"); 
$server = new SoapServer("catalog.wsdl"); 
$server->addFunction(array("getCatalogEntry", "getTestMessage")); 
$server->handle(); 


?>

我的soap-client.PHP

<?PHP  
  $client = new SoapClient("catalog.wsdl");
  $catalogId = 'catalog2';
  $testMessage = "Some Message";
  $response = $client->getCatalogEntry($catalogId);
  $response2 = $client->getTestMessage($testMessage);

  echo $response;
  echo "<br /><br />";
  echo $response2;
?>

和我得到的错误:

[31-Jan-2011 04:30:29] PHP Fatal error:  Uncaught SoapFault exception: [Client] Function ("getTestMessage") is not a valid method for this service in /mnt/stor2-wc2-dfw1/441352/www.thevinylfactory.com/web/content/ws/soap-client.PHP:6
Stack trace:
#0 [internal function]: SoapClient->__call('getTestMessage', Array)
#1 /mnt/stor2-wc2-dfw1/441352/www.thevinylfactory.com/web/content/ws/soap-client.PHP(6): SoapClient->getTestMessage('Some Message')
#2 {main}
  thrown in /mnt/stor2-wc2-dfw1/441352/www.thevinylfactory.com/web/content/ws/soap-client.PHP on line 6

有人可以帮我这个吗?先感谢您!

解决方法:

好的,我找到了一个解决方案 – 似乎wsdl文件正在缓存.我发布这个以防万一其他人会遇到类似的问题.您所要做的就是在.htaccess文件中添加以下行:

PHP_value soap.wsdl_cache_enabled 0

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读