【问题标题】:Silverlight and PHP nuSOAP communication problemSilverlight 和 PHP nuSOAP 通信问题
【发布时间】:2010-12-07 10:27:54
【问题描述】:

我正在编写一个silverlight 应用程序,我想在其中调用使用NuSOAP 编写的php web 服务。这是webservice的WSDL

      <?xml version="1.0" encoding="ISO-8859-1" ?> 
- <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:currencywebservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:currencywebservice">
- <types>
- <xsd:schema targetNamespace="urn:currencywebservice">
  <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> 
  <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" /> 
  </xsd:schema>
  </types>
  <message name="GetAllCurrenciesRequest" /> 
- <message name="GetAllCurrenciesResponse">
  <part name="return" type="xsd:string" /> 
  </message>
- <portType name="currencywebservicePortType">
- <operation name="GetAllCurrencies">
  <documentation>Get all currencies available</documentation> 
  <input message="tns:GetAllCurrenciesRequest" /> 
  <output message="tns:GetAllCurrenciesResponse" /> 
  </operation>
  </portType>
- <binding name="currencywebserviceBinding" type="tns:currencywebservicePortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> 
- <operation name="GetAllCurrencies">
  <soap:operation soapAction="urn:currencywebservice#GetAllCurrencies" style="rpc" /> 
- <input>
  <soap:body use="literal" namespace="urn:currencywebservice" /> 
  </input>
- <output>
  <soap:body use="literal" namespace="urn:currencywebservice" /> 
  </output>
  </operation>
  </binding>
- <service name="currencywebservice">
- <port name="currencywebservicePort" binding="tns:currencywebserviceBinding">
  <soap:address location="http://localhost/extras/currency/currencyservice.php" /> 
  </port>
  </service>
  </definitions>

当我调用 web 服务时,它给出了一个异常

The content type text/html of response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly

服务的php端是

<?php
// Pull in the NuSOAP code
require_once('../../lib/tools/nusoap/nusoap.php');

$ns = "urn:currencywebservice"; 
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('currencywebservice', $ns);
$server->xml_encoding = "utf-8";
$server->soap_defencoding = "utf-8";
$server->wsdl->schemaTargetNamespace = $ns;

$server->register('GetAllCurrencies',
array(),
array('return' => 'xsd:string'),
$ns,
$ns."#GetAllCurrencies",
'rpc',
'literal',
'Get all currencies available');

// Define the method as a PHP function
function GetAllCurrencies() {
        return "test return";
}
// Use the request to (try to) invoke the service
header('Content-Type: text/xml; charset=utf8');
$server->service($HTTP_RAW_POST_DATA);
?>

请帮我看看这是什么问题?

【问题讨论】:

    标签: php silverlight soap web-services nusoap


    【解决方案1】:

    在 register 方法中尝试将“$use”参数设置为“literal”而不是“encoded”。

    【讨论】:

      【解决方案2】:

      看起来服务客户端(Silverlight?)期望服务调用的结果为text/xml,采用UTF-8 编码,但您的PHP 将其返回为text/htmltext/html 是 PHP 的默认内容类型,除非您通过 header 命令指定不同的内容类型。

      因此,您可能想尝试将以下内容添加到您的 PHP 文件/服务的顶部:

      header('Content-Type: text/xml');
      

      还可能需要确保您的文本编码是 UTF-8。

      【讨论】:

      • 感谢琼斯的帮助!如果可行,我会试一试。
      • 现在我收到此错误“无法识别的消息版本”。有什么想法吗?
      • 使用您所做的任何代码更新来更新您的原始问题。
      • 我已经更新了以下两行代码“header('Content-Type: text/xml; charset=utf8');”和 "$server->xml_encoding = "utf-8";"查看原始问题
      • 作为工作,我使用了 WebClient 实例,并自己解析了响应。
      【解决方案3】:

      请使用原生 PHP SoapClient 而不是 nuSoap。这是过去的遗物。

      【讨论】:

      • 问题是并非每个 PHP 实例都安装/编译了本机 SoapClient。我宁愿使用 Zend 框架或本机 PHP SOAP 库,但受到我可用版本的限制。由于各种原因,重新编译 PHP 不是一种选择。所以 NuSOAP 是两害相权取其轻。
      猜你喜欢
      • 2011-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-12
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多