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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.