English 中文(简体)
Silverlight and PHP nuSOAP communication problem
原标题:

I am writting a silverlight application in which I want to call the php webservice written using NuSOAP. here is the WSDL of webservice

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

When I call the webservice it gives an exception

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

The php side of service is

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

Please help me out what is this problem?

问题回答

In the register method try putting the $use parameter as literal instead of encoded .

It looks like the Service Client (Silverlight?) is expecting the result of the Service call to be text/xml with a UTF-8 encoding, but your PHP is returning it as text/html. text/html is the default content type for PHP unless you specify a different content type through the header command.

So, you may want to try adding the following to the top of your PHP file/service:

header( Content-Type: text/xml );

Also may want to ensure that your text encoding is UTF-8.

Please use the native PHP SoapClient instead of nuSoap. It s a relic of the past.





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签