0

我正在编写一个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>

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

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);
?>

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

4

3 回答 3

1

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

于 2010-10-19T06:02:18.477 回答
0

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

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

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

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

于 2010-04-13T19:17:51.883 回答
0

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

于 2010-10-01T07:09:17.917 回答