Jump to content

PHP WSDL Help Needed


jimatcaledonia

Recommended Posts

Hi all,

 

I am a Junior Developer, I have taken over someone's implementation of a web service and am struggling.

 

They used python to access the methods.

 

I can access the web service via Python and connect it to our databases, but it is really slow.

 

I believe that PHP would make it faster, but I am not able to make the right connections.

 

Any help would be really appreciated.

 

I have included some code snippets below,

 

Thank you,

 

Jim

 

 

 

 

 

######################################################################

Python

######################################################################

#!/usr/bin/python

 

######################################################################

# Module imports

######################################################################

from suds.client import Client

from suds.wsse import *

from xml.dom import minidom

import MySQLdb

 

 

######################################################################

# Address Interface.

######################################################################

 

class Address(object):

    def __init__(self, ttl=600):

        # Constants.

        self._USERNAME = 'username'

        self._PASSWORD = 'password'

self._address_search_url = 'https://jim.svc?wsdl'

 

        # SOAP security setup.

        self._security = Security()

        self._token = UsernameToken(self._USERNAME, self._PASSWORD)

        self._security.tokens.append(self._token)

       

        #print 'Starting Address Search.'

        self._address_search_client = Client(self._address_search_url)

        self._address_search_client.set_options(wsse=self._security)

       

        # Addresses.  ########################################################

    def address_search_by_postcode(self, postcode):

        RegsRegionType = self._address_search_client.factory.create('ns1:RegsRegionType')

        regs_region = RegsRegionType.Scotland 

        address_data = self._address_search_client.service.SearchAddressByPostCode(regs_region, RegisterType.Domestic, postcode, '')

 

        addrs = []

        for addr in address_data.keys.string:

            address_dom = minidom.parseString(addr.encode('utf-8'))

            ob = {}

 

  #Get addr details

 

            addrs.append(ob)

        return addrs

   

      

######################################################################

def get_data(d, t):

    try:

        return d.getElementsByTagName(t)[0].childNodes[0].data

    except:

        return None

 

######################################################################

PHP

######################################################################


<?php

    error_reporting(E_ALL);

     ini_set('display_errors', 'on');

 

     $username = "username";

     $password = 'password';

     $wsdl = "https://jim.svc?wsdl";

 

     // SOAP security setup

     $options = array(

          'login' => $username,

          'password' => $password,

      );

///////////////////////////////////////////////////////////////////////////////

Connect

//////////////////////////////////////////////////////////////////////////////

        $client = new SoapClient($wsdl, $options);

 

//////////////////////////////////////////////////////////////////////////////

         define wsse security

//////////////////////////////////////////////////////////////////////////////


        $headerContent = "<o:Security xmlns:o=\"$securityNamespace\">

                    <o:UsernameToken>

                    <o:Username>USERNAME</o:Username>

                    <o:Password>PASSWORD</o:Password>

                    </o:UsernameToken>

                </o:Security>";

        $headerVar = new SoapVar($headerContent, XSD_ANYXML, null, null, null);

        $header = new SoapHeader($securityNamespace, 'o:Security', $headerVar);

 

//////////////////////////////////////////////////////////////////////////////

       Authenticate

//////////////////////////////////////////////////////////////////////////////

         $client->__setSoapHeaders(array($header));

 

        var_dump($client->__getFunctions());

 

         try{

               $result = $client->SearchAddressByPostCode($regsRegion, $registerType, $postCode, " ");

                print_r($result);

           }catch (SoapFault $exception){

                       var_dump($exception);

           }

print('done');

?>

 

 


//////////////////////////////////////////////////////////////////////////////

     END

//////////////////////////////////////////////////////////////////////////////

 

Hope someone can help and point me in the right direction

 


Thanks

 

JIm


 

Link to comment
https://forums.phpfreaks.com/topic/290743-php-wsdl-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.