2010-04-13 2 views
0

Я пишу приложение silverlight, в котором я хочу позвонить в php webservice, написанный с использованием NuSOAP. вот WSDL из WebServiceПроблема связи с Silverlight и PHP nuSOAP

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

Пожалуйста, помогите мне, что эта проблема ?

ответ

0

Похоже, что Клиент службы (Silverlight?) Ожидает, что результатом Сервисного вызова будет text/xml с кодировкой UTF-8, но ваш PHP возвращает его как text/html. text/html - это тип содержимого по умолчанию для PHP, если вы не укажете другой тип контента с помощью команды header.

Таким образом, вы можете попробовать добавить следующие строки в верхней части PHP файла/услуги:

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

Также может потребоваться для того, чтобы текст кодировки UTF-8.

+0

Спасибо за помощь! Я попробую, если это сработает. –

+0

Теперь я получаю эту ошибку «Неопознанная версия сообщения». Есть идеи? –

+0

Обновите свой исходный вопрос с помощью любых сделанных вами обновлений кода. –

0

Вместо nuSoap используйте собственный PHP SoapClient. Это реликвия прошлого.

+0

Проблема заключается в том, что не каждый экземпляр PHP имеет встроенный или скомпилированный родной SoapClient. Я бы предпочел использовать структуру Zend или собственную PHP-библиотеку SOAP, но ограничена версией, которую у меня есть. И по разным причинам перекомпиляция PHP не является вариантом. Таким образом, NuSOAP является меньшим из двух зол. – Kingsolmn

1

В методе регистрации попробуйте поместить параметр $ use в качестве 'literal' вместо 'encoded'.

+0

Позвольте мне проверить его, если он работает? –

Смежные вопросы