Search the Community
Showing results for tags 'wsdl'.
-
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 ////////////////////////////////////////////////////////////////////////////// $securityNamespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; $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
-
I'm new to soap and webservices , and wanting to know do I have to use soap with a wsdl file, or can I use something else like json?
-
I did some searching on this issue and all the solutions that seemed to be similar did not work for my problem. Anyways, I need to make a SOAP call with a sequence in it, yet soapClient doesn't seem to be converting my object into the correct soap call (it is leaving out the sequence). Below is the part of the wsdl that I cant seem to get, along with the object that I am sending, and lastly the request that soapClient is translating my object into. Any help would be much appreciated. wsdl: <xs:element minOccurs="0" name="option.list"> <xs:complexType> <xs:complexContent> <xs:extension base="cmn:ArrayType"> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="option.list"> <xs:complexType> <xs:complexContent> <xs:extension base="cmn:StructureType"> <xs:sequence> <xs:element minOccurs="0" name="SubItemId" nillable="true" type="cmn:DecimalType"/> <xs:element minOccurs="0" name="SubOptions" nillable="true" type="cmn:StringType"/> <xs:element minOccurs="0" name="SubItemName" nillable="true" type="cmn:StringType"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> </xs:element> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> </xs:element> my object: [option.list] => Array ( [0] => Array ( [option.list] => Array ( [SubItemId] => 0 [SubOptions] => <?xml version="1.0" encoding="UTF-8" standalone="yes"?><form><select id="DBMS" label="DBMS type:" style="combo">MS SQL<option label="" /><option id="0" label="DB2">DB2</option><option id="1" label="IMS">IMS</option><option id="2" label="MS SQL">MS SQL</option><option id="3" label="Oracle">Oracle</option><option id="4" label="UDB">UDB</option></select><select id="Type" label="lation Type:" style="combo">Add New Instance<option label="" /><option id="0" label="Add New Environment">Add New Environment</option><option id="1" label="Add New Instance">Add New Instance</option><option id="2" label="Add New Database">Add New Database</option><option id="3" label="Modify Environment">Modify Environment</option><option id="4" label="Modify Instance">Modify Instance</option><option id="5" label="Modify Database">Modify Database</option><option id="6" label="Retire Environment">Retire Environment</option><option id="7" label="Retire Instance">Retire Instance</option><option id="8" label="Retire Database">Retire Database</option></select><select id="Complexity" label="xity:" style="combo">Complex [+$2500.00]<option label="" /><option id="0" label="Simple [+$500.00]">Simple [+$500.00]</option><option id="1" label="Medium [+$1000.00]">Medium [+$1000.00]</option><option id="2" label="Complex [+$2500.00]">Complex [+$2500.00]</option></select><select id="RecoveryTier" label="rability Tier:" style="combo">Tier 2<option label="" /><option id="0" label="Tier 1">Tier 1</option><option id="1" label="Tier 2">Tier 2</option><option id="2" label="Tier 3">Tier 3</option></select><select id="Backup" label=" Backup Required?" style="combo">Yes<option label="" /><option id="0" label="Yes">Yes</option><option id="1" label="No">No</option></select><select id="Replication" label=" tables require replication?" style="combo">UDB Dprop<option label="" /><option id="0" label="UDB Dprop">UDB Dprop</option><option id="1" label="Goldengate">Goldengate</option><option id="2" label="ASM">ASM</option><option id="3" label="No">No</option></select></form> [SubItemName] => DB Modification ) ) ) generated request: <ns1:option.list><ns1:option.list/></ns1:option.list>
- 3 replies
-
- soap
- soapclient
-
(and 2 more)
Tagged with:
-
I am new here, and not sure if this is the right place to put this, anyways I had a question about wsdl2php and php Soap Client. I need to send SOAP requests from a PHP applications and I am trying to use wsdl2php to generate the needed classes. (Did this a few times in the past with no issues.) Anyways, this time I am running into an issue where the WSDL has '.' in the element names and there are also nested element names. below is a section of the wsdl that shows this. -<xs:element name="option.list" minOccurs="0">-<xs:complexType>-<xs:complexContent>-<xs:extension base="cmn:ArrayType">-<xs:sequence>-<xs:element name="option.list" minOccurs="0" maxOccurs="unbounded">-<xs:complexType>-<xs:complexContent>-<xs:extension base="cmn:StructureType">-<xs:sequence><xs:element name="FromBundle" type="cmn:DecimalType" nillable="true" minOccurs="0"/><xs:element name="SubItemId" type="cmn:DecimalType" nillable="true" minOccurs="0"/><xs:element name="SubItemName" type="cmn:StringType" nillable="true" minOccurs="0"/><xs:element name="SubItemType" type="cmn:StringType" nillable="true" minOccurs="0"/><xs:element name="SubOptions" type="cmn:StringType" nillable="true" minOccurs="0"/><xs:element name="SubOptionValidations" type="cmn:StringType" nillable="true" minOccurs="0"/><xs:element name="SubOptionCosts" type="cmn:StringType" nillable="true" minOccurs="0"/><xs:element name="SubItemOptionInBundle" type="cmn:StringType" nillable="true" minOccurs="0"/><xs:element name="SubItemQuantityInBundle" type="cmn:DecimalType" nillable="true" minOccurs="0"/><xs:element name="SubItemOptionIdInBundle" type="cmn:StringType" nillable="true" minOccurs="0"/></xs:sequence></xs:extension></xs:complexContent></xs:complexType></xs:element></xs:sequence></xs:extension></xs:complexContent></xs:complexType></xs:element> So, wsdl2php is creating classes with a '.' in them and also declaring classes twice because of the nested element names. If anyone has any ideas on how I can get these soap requests working, or have seen this before, I would be very apprciative. Thanks, Mike
-
Dear Gurus, I need to write an application that can send and receive SOAP messages, following a WSDL specification supplied by a third party. I am a bit stuck of how to exactly follow it and remain functional. Here is a snippet from the WSDL: 01: <s:element name="SubscriptionRequestContainer"> 02: <s:complexType> 03: <s:sequence> 04: <s:element minOccurs="1" maxOccurs="1" name="SubscriptionRequest" type="tns:SubscriptionRequestItemCollection"> 05: <s:unique name="uniqueUnitId"> 06: <s:selector xpath="Add|Renew|Delete"/> 07: <s:field xpath="@UnitId"/> 08: </s:unique> 09: </s:element> 10: </s:sequence> 11: </s:complexType> 12: </s:element> 13: 14: <s:complexType name="SubscriptionRequestItemCollection"> 15: <s:sequence> 16: <s:element minOccurs="0" maxOccurs="unbounded" name="Add" type="tns:SubscriptionRequestAddItem" /> 17: <s:element minOccurs="0" maxOccurs="unbounded" name="Renew" type="tns:SubscriptionRequestRenewItem" /> 18: <s:element minOccurs="0" maxOccurs="unbounded" name="Delete" type="tns:SubscriptionRequestDeleteItem" /> 19: </s:sequence> 20: </s:complexType> I must admit I am new to WSDL. That's why I do not fully understand what lines 05 - 08 mean. It must be some definition of how to make sure the names of sections at the same hierarchical level are unique in the resulting SOAP request, thus they can be accessed independently, by name. Can someone help me interpret this definition and explain what the names of the resulting SubscriptionRequest entries should be? Could they be Activate@001, Activate@099, Renew@012 - or how to properly interpret lines 05-08 above? Big-big thanks in advance, Tom
-
Hi All, I'm not 100% sure if this is the place to be posting for help with this. I have managed to get some source code for a SMS PHP page. However I am having some problems getting it to work, mainly because I'm not 1005 sure how to configure it, and if I need to make any toher changes to the code in order to incorporate my SMS gateway. The error message I am getting is: "SMS Sending Failed Message:Network error unable to send the message", this mesage is however coded into the code. Below is the code of the 4 different pages: HTML Page where message is created <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>SMS Sending Service</title> <style type="text/css"> body { font-family:Verdana,Arial,sans-serif; font-size:100%; } td { vertical-align:top; } input[type=submit] { padding:5px 10px; } </style> <script type="text/javascript" src="send.js"></script> </head> <body> <h1>SMS Sending Service</h1> <form action="send.php" method="post"> <table border="0" cellpadding="5" style="background:#F7F7F7;border:1px solid #CCC;border-radius:5px;-moz-border-radius:5px;"> <tr> <td><label for="method">Tipo di SMS:</label></td> <td> <select name="method" id="method"> <option value="classic">Classic</option> <option value="report">Classic con notifica</option> <option value="basic">Basic</option> </select> </td> </tr> <tr> <td><label for="recipients">Your Valentine's Number: </label></td> <td> <span id="recipients"> <div><input type="text" name="recipients[]" value="27" /></div> </span> <a href="javascript:;" onclick="addRecipient();"><small>Add Another Valentine</small></a> </td> </tr> <tr> <td><label for="text">Message: </label></td> <td><textarea name="text" id="text" cols="30" rows="10"></textarea></td> </tr> <tr> <td></td> <td> <small> Characters Remaining: <span id="leftChars" style="color:#F00;">0</span> / <b id="messageMaxLength">765</b> (<span id="numberOfSMS" style="color:#39b54a;">1</span>) </small> </td> </tr> <tr> <td><label for="sender_number">Sender's Number: </label></td> <td><input type="text" name="sender_number" id="sender_number" /> <small>Eg 27741123456</small></td> </tr> <tr> <td><label for="sender_string">Alphanumeric Sender: </label></td> <td><input type="text" name="sender_string" id="sender_string" maxlength="11" /> <small>Max 11 Characters</small></td> </tr> <tr> <td><label for="charset">Charset</label></td> <td> <select name="charset" id="charset"> <option value="ISO-8859-1">ISO-8859-1</option> <option value="UTF-8">UTF-8</option> </select> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" value="Send Message" name="submit" /> </td> </tr> </table> </form> </body> </html> PHP Send page <?php // IMPORTANT: // ENTER YOUR CREDENTIALS HERE VM ini_set('soap.wsdl_cache_enabled',0); ini_set('soap.wsdl_cache_ttl',0); define('VM_WSDL', 'https://myhostserver/WebsiteData/WebsiteDataEndpoint?wsdl'); define('VM_USERNAME','MyGateWayUsername'); define('VM_PASSWORD','MyGateWayPassword'); require('validate.php'); // Collect post data from form $method = $_POST['method']; $recipients = $_POST['recipients']; $text = $_POST['text']; $sender_number = $_POST['sender_number']; $sender_string = $_POST['sender_string']; $charset = $_POST['charset']; $result = VMGatewaySendSMS(VM_USERNAME, VM_PASSWORD, $recipients, $text, $method, $sender_number, $sender_string, $charset); if($result['status']=='success') { echo '<b style="color:#8dc63f;">SMS Sent Successfully</b><br/>'; echo '<b>SMS rimanenti:</b>'.$result['remaining_sms']; } if($result['status']=='failed') { echo '<b style="color:#ed1c24;">SMS Sending Failed</b><br/>'; if(isset($result['code'])) { echo '<b>Codice:</b>'.$result['code'].'<br/>'; } echo '<b>Message:</b>'.urldecode($result['message']); } ?> Send.js file var SMS_CLASSIC_MAX_LENGTH = 765, SMS_BASIC_MAX_LENGTH = 1404, CURRENT_SMS_LENGTH = 765; var translations = Array(); translations['ErrorTextMoreThan']='Attenzione! Il testo non puo\' essere piu\' lungo di '; translations['ErrorChars']=' caratteri!\n'; function addRecipient() { var newRecipient = document.createElement('div'); newRecipient.innerHTML = '<input type="text" name="recipients[]" value="27" /> <a href="javascript:;" onclick="removeRecipient(this.parentNode);"><small>Remove</small></a>'; document.getElementById("recipients").appendChild(newRecipient); } function removeRecipient(obj) { document.getElementById("recipients").removeChild(obj); } window.onload = function() { var msgMaxLen = document.getElementById("messageMaxLength"); document.getElementById("method").onchange = function(){ switch(this.value) { case "classic": case "report": msgMaxLen.innerHTML = SMS_CLASSIC_MAX_LENGTH; CURRENT_SMS_LENGTH = SMS_CLASSIC_MAX_LENGTH; charLeft(); break; case "basic": msgMaxLen.innerHTML = SMS_BASIC_MAX_LENGTH; CURRENT_SMS_LENGTH = SMS_BASIC_MAX_LENGTH; charLeft(); break; } }; document.getElementById("text").onkeyup = function(){ charLeft(); }; }; function charLeft(){ var max = CURRENT_SMS_LENGTH; var smsText = document.getElementById("text").value; var doubleChars = 0; if(smsText==="") { var length = 0; } else { var length = getRealLengthFor(smsText,false); doubleChars = getRealLengthFor(smsText,true); } if (length > max){ document.getElementById("text").value = smsText.substring(0, max-doubleChars); alert(translations['ErrorTextMoreThan'] + max + translations['ErrorChars']); } var leftChars = length; if (leftChars < 0){ leftChars = 0; } document.getElementById("leftChars").innerHTML = leftChars; var numberOfSMS = document.getElementById("numberOfSMS"); var actualNumberOfSMS = 0; switch(max) { case SMS_CLASSIC_MAX_LENGTH: if(length<=160) { numberOfSMS.innerHTML = '1'; } if(length>160) { actualNumberOfSMS = Math.floor((length-1) / 153) + 1; numberOfSMS.innerHTML = actualNumberOfSMS; } break; case SMS_BASIC_MAX_LENGTH: numberOfSMS.innerHTML = getNumberOfSegmentForBasic(smsText.length, smsText); break; } } //from JAVA: //var SPECIAL_CHARS = Array('[', '\\', ']', '^', '{', '|', '}', '~', '¬', 8364); var SPECIAL_CHARS = Array("\x5B", "\x5C", "\x5D", "\x5E", "\x7B", "\x7C", "\x7D", "\x7E", 8364, 49792, 14844588); var CHAR_TO_CUT_BASIC = Array(' ', '.', ',', '?', '!'); // Fa il check se una variabile e' null o vuota function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; } // Aggiungo un metodo alla classe string // toCharArray esistente in java String.prototype.toCharArray = function() { var charArr=new Array(); for(var i=0;i<this.length;i++) charArr[i]=this.charAt(i); return charArr; }; // isIntInTheArray // Cerca nell'array chars se e' presente il carattere c // Parametri: // char c, char[] chars function isIntInTheArray(c, chars) { for(var i=0;i<chars.length;i++) { if(chars[i] == c || chars[i] == c.charCodeAt(0)) return true; } return false; } // getRealLengthFor // Parametri: // String s // Return int function getRealLengthFor(s,getDoubleChars) { if (isEmpty(s)) return 0; var chars = s.toCharArray(); var numberOfSpecialChars = 0; for (var k=0; k<chars.length; k++) { if (isIntInTheArray(chars[k], SPECIAL_CHARS)) { numberOfSpecialChars++; } } if(getDoubleChars === true) return numberOfSpecialChars; return s.length + numberOfSpecialChars; } // Conteggio SMS Basic - Mirko Mariani // Traduzione dall'algoritmo JAVA // Return Int // Parametri: // Integer len, String s function getNumberOfSegmentForBasic(len, s) { if (len <= 160) return 1; var leftStringToSplit = s; var segmentNumber = 0, cycle = 0, segmentLength = 0; var c = 'c'; var charForLeftString = null; while (!isEmpty(leftStringToSplit)) { var indexOfEndSegment = -1; var numberOfSpecialChars = 0; if ( cycle == 0 ) { segmentLength = 156; } else { segmentLength = 156; } // Check if we reached the last segment if ( getRealLengthFor( leftStringToSplit , false) > segmentLength ) { charForLeftString = leftStringToSplit.toCharArray(); for ( var k = 0; k < charForLeftString.length; k++ ) { if ( isIntInTheArray( charForLeftString[k], SPECIAL_CHARS ) ) { numberOfSpecialChars++; } } indexOfEndSegment = segmentLength - numberOfSpecialChars; // go to the point where cut the text var charChecked = 0; var charForCuttingFound = false; // search till the 15 char back while ( charChecked < 15 && !charForCuttingFound ) { c = leftStringToSplit.charAt( indexOfEndSegment - charChecked ); if ( isIntInTheArray( c, CHAR_TO_CUT_BASIC ) ) { segmentNumber++; charForCuttingFound = true; } else { charChecked++; } } // if no char has been found the string will be cut at the end of the segment length -> put the charChecked to 0 to // use the substring method below to determine the left string still to split if (!charForCuttingFound ) { segmentNumber++; charChecked = 0; } // change the left string still to split leftStringToSplit = leftStringToSplit.substring( indexOfEndSegment - charChecked, leftStringToSplit.length ); } else { // reset to end the cycle leftStringToSplit = ""; segmentNumber++; } cycle++; } return segmentNumber; } Validate.php <?php define("NET_ERROR", "Network+error+unable+to+send+the+message"); define("SENDER_ERROR", "You+can+specify+just+one+type+of+sender%2C+numeric+or+alphanumberic"); function do_post_request($url, $data, $optional_headers = null){ if(!function_exists('curl_init')) { $params = array( 'http' => array( 'method' => 'POST', 'content' => $data ) ); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { return 'status=failed&message='.NET_ERROR; } $response = @stream_get_contents($fp); if ($response === false) { return 'status=failed&message='.NET_ERROR; } return $response; } else { $ch = curl_init(); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_TIMEOUT,60); curl_setopt($ch,CURLOPT_USERAGENT,'Generic Client'); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch,CURLOPT_URL,$url); if ($optional_headers !== null) { curl_setopt($ch,CURLOPT_HTTPHEADER,$optional_headers); } $response = curl_exec($ch); curl_close($ch); if(!$response){ return 'status=failed&message='.NET_ERROR; } return $response; } } function VMGatewaySendSMS($username,$password,$recipients,$text,$sms_type='basic',$sender_number='',$sender_string='',$charset='',$optional_headers=null) { $url = 'https://Myhostserver/WebsiteData/WebsiteDataEndpoint?wsdl'; switch($sms_type) { case 'classic': $method='send_sms_classic'; break; case 'report': $method='send_sms_classic_report'; break; case 'basic': default: $method='send_sms_basic'; } $parameters = 'method=' .urlencode($method).'&' .'username=' .urlencode($username).'&' .'password=' .urlencode($password).'&' .'text=' .urlencode($text).'&' .'recipients[]='.implode('&recipients[]=',$recipients) ; if($sender_number != '' && $sender_string != '') { parse_str('status=failed&message='.SENDER_ERROR,$result); return $result; } $parameters .= $sender_number != '' ? '&sender_number='.urlencode($sender_number) : ''; $parameters .= $sender_string != '' ? '&sender_string='.urlencode($sender_string) : ''; switch($charset) { case 'UTF-8': $parameters .= '&charset='.urlencode('UTF-8'); break; case '': case 'ISO-8859-1': default: } parse_str(do_post_request($url,$parameters,$optional_headers),$result); return $result; } ?>