Domanda

Ho un modulo di Drupal 6 che fornisce un servizio Web utilizzando nusoap. Posso accedere al servizio con il php ma il servizio non è accessibile da un'applicazione .NET. Se io invece utilizzare lo stesso codice per fornire un servizio web in Drupal 7 è possibile accedervi da un'applicazione .NET.

Questa è la funzione che fornisce il servizio web:

function _provide_nusoap_server(){

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

  // Create the server instance
  $server = new soap_server();

  global $base_url;

  // Initialize WSDL support
  $server->configureWSDL('mynamespace', 'urn:mynamespace', $base_url.'/mysoap');

  // tämä paluuarvoille
  $server->wsdl->addComplexType(
    'stringArray',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')
    ),
    'xsd:string'
  );

  // Register the method
  $server->register('mysoap_addModifyProduct',      // method name
      array(      
      'salasana' => 'xsd:string',
      'rekkariId' => 'xsd:int',                     // to identify event in rekisteri. Later on id can be used to update or delete certain event      
      //'op' => 'xsd:string',                       // op should be 'insert' or 'update'
      'tuotenimi' => 'xsd:string',
  ),
      array(
        'ret' => 'tns:stringArray',
      ),    
      'urn:mynamespace',                      // namespace
      'urn:mynamespace#mysoap_addModifyProduct',      // soapaction
      'rpc',                                     // style
      'encoded',                                 // use
      'Adds stuff to Drupal database'            // documentation
  );

  // Use the request to (try to) invoke the service
  global $HTTP_RAW_POST_DATA;
  $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  $server->service($HTTP_RAW_POST_DATA);

}

Ed ecco il file 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:mynamespace" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:mynamespace">
<types>
<xsd:schema targetNamespace="urn:mynamespace"
>
 <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
 <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
 <xsd:complexType name="stringArray">
  <xsd:complexContent>
   <xsd:restriction base="SOAP-ENC:Array">
    <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]"/>
   </xsd:restriction>

  </xsd:complexContent>
 </xsd:complexType>
</xsd:schema>
</types>
<message name="mysoap_addModifyProductRequest">
  <part name="salasana" type="xsd:string" />
  <part name="rekkariId" type="xsd:int" />
  <part name="tuotenimi" type="xsd:string" /></message>
<message name="mysoap_addModifyProductResponse">
  <part name="ret" type="tns:stringArray" /></message>
<portType name="mynamespacePortType">

  <operation name="mysoap_addModifyProduct">
    <documentation>Adds stuff to Drupal database</documentation>
    <input message="tns:mysoap_addModifyProductRequest"/>
    <output message="tns:mysoap_addModifyProductResponse"/>
  </operation>
</portType>
<binding name="mynamespaceBinding" type="tns:mynamespacePortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="mysoap_addModifyProduct">

    <soap:operation soapAction="urn:mynamespace#mysoap_addModifyProduct" style="rpc"/>
    <input><soap:body use="encoded" namespace="urn:mynamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
    <output><soap:body use="encoded" namespace="urn:mynamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
  </operation>
</binding>
<service name="mynamespace">
  <port name="mynamespacePort" binding="tns:mynamespaceBinding">
    <soap:address location="[the url of the service]/mysoap"/>
  </port>
</service>

</definitions>
È stato utile?

Soluzione

soluzione per questo problema è quello di salvare il -file WSDL come un file fisico al server web. L'aria qui è che ogni volta che il servizio cambia il WSDL-file deve essere salvato di nuovo.

Un'alternativa e forse migliore idea sarebbe quella di utilizzare i servizi del modulo http://drupal.org/project/services

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a drupal.stackexchange
scroll top