How to get Target namespace for SOAP non-wsdl webservice - php

How do you get the URI for using the SOAPClient which doesn't have the WSDL. The user has not provided us with the WSDL, but wanted to use their webservice using SOAP to get some information. I am looking for how to do it on PHP.
The confusion part is how to identify the URI value (target namespace). Based on their documentation,below is the sample they provided for SOAP call to me made.
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.
**POST /webservices/wssamples/service.asmx HTTP/1.1
Host: www.samplecomponents.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length**
```
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<QueryAvailability xmlns="http://www.samplecomponents.com/webservices/">
<program_id>string</program_id>
<security_id>string</security_id>
<part_number>string</part_number>
</QueryAvailability>
</soap12:Body>
</soap12:Envelope>
```
**RESPONSE**
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<QueryAvailabilityResponse xmlns="http://www.samplecomponents.com/webservices/">
<QueryAvailabilityResult xmlns="http://www.samplecomponents.com/schemas/sample_availability.xsd">
<timestamp>dateTime</timestamp>
<item_count>unsignedInt</item_count>
<items>
<item>
<part_id>unsignedInt</part_id>
<manufacturer_part_number>string</manufacturer_part_number>
<stock_source>string</stock_source>
<digikey_part_number>string</digikey_part_number>
<description>string</description>
<quantity_available>unsignedInt</quantity_available>
<break_quantity>unsignedInt</break_quantity>
<rohs_compliant>bytes</rohs_compliant>
<flag_non_stock>boolean</flag_non_stock>
<flag_obsolete>boolean</flag_obsolete>
<flag_static_sensitive>boolean</flag_static_sensitive>
</item>
<item>
<part_id>unsignedInt</part_id>
<manufacturer_part_number>string</manufacturer_part_number>
<stock_source>string</stock_source>
<digikey_part_number>string</digikey_part_number>
<description>string</description>
<quantity_available>unsignedInt</quantity_available>
<break_quantity>unsignedInt</break_quantity>
<rohs_compliant>bytes</rohs_compliant>
<flag_non_stock>boolean</flag_non_stock>
<flag_obsolete>boolean</flag_obsolete>
<flag_static_sensitive>boolean</flag_static_sensitive>
</item>
</items>
</QueryAvailabilityResult>
</QueryAvailabilityResponse>
</soap12:Body>
</soap12:Envelope>
**HTTP POST**
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.
POST /webservices/wssamples/service.asmx/QueryAvailability HTTP/1.1
Host: www.samplecomponents.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length
program_id=string&security_id=string&part_number=string```
**RESPONSE**
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<sample_availability xmlns="http://www.samplecomponents.com/schemas/sample_availability.xsd">
<timestamp>dateTime</timestamp>
<item_count>unsignedInt</item_count>
<items>
<item>
<part_id>unsignedInt</part_id>
<manufacturer_part_number>string</manufacturer_part_number>
<stock_source>string</stock_source>
<digikey_part_number>string</digikey_part_number>
<description>string</description>
<quantity_available>unsignedInt</quantity_available>
<break_quantity>unsignedInt</break_quantity>
<rohs_compliant>bytes</rohs_compliant>
<flag_non_stock>boolean</flag_non_stock>
<flag_obsolete>boolean</flag_obsolete>
<flag_static_sensitive>boolean</flag_static_sensitive>
</item>
<item>
<part_id>unsignedInt</part_id>
<manufacturer_part_number>string</manufacturer_part_number>
<stock_source>string</stock_source>
<digikey_part_number>string</digikey_part_number>
<description>string</description>
<quantity_available>unsignedInt</quantity_available>
<break_quantity>unsignedInt</break_quantity>
<rohs_compliant>bytes</rohs_compliant>
<flag_non_stock>boolean</flag_non_stock>
<flag_obsolete>boolean</flag_obsolete>
<flag_static_sensitive>boolean</flag_static_sensitive>
</item>
</items>
</sample_availability>
These is no reference to URI or target namespace to be supplied on this documentation. Any help much appreciated.

The "target namespace" is simply the XML namespaces of the element inside the SOAP body - in this case the QueryAvailability and QueryAvailabilityResponse elements which would be the root of the document if all the SOAP wrapping wasn't there.
So you just need to read the xmlns attributes in the sample, which show those elements to be in the namespace http://www.samplecomponents.com/webservices/

Related

asmx HTTP Post request with parameters

our company has a .net base website
a few days ago we request a webservice from our website programmer and yesterday he sent me a URL
when i open the URL from localhost its shown a page that i can choose one of my four method (function) that we request to programming.
by choosing one of them a new page has boon shown as follow:
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /webservices/findstatus.asmx HTTP/1.1 Host: localhost
Content-Type: text/xml; charset=utf-8 Content-Length: length
SOAPAction: "http://tempuri.org/FindWith_CodeR_Serail"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FindWith_CodeR_Serail xmlns="http://tempuri.org/">
<CodeReception>int</CodeReception>
<Serial>string</Serial>
</FindWith_CodeR_Serail>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FindWith_CodeR_SerailResponse xmlns="http://tempuri.org/">
<FindWith_CodeR_SerailResult>string</FindWith_CodeR_SerailResult>
</FindWith_CodeR_SerailResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.
POST /webservices/findstatus.asmx HTTP/1.1 Host: localhost
Content-Type: application/soap+xml; charset=utf-8 Content-Length:
length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<FindWith_CodeR_Serail xmlns="http://tempuri.org/">
<CodeReception>int</CodeReception>
<Serial>string</Serial>
</FindWith_CodeR_Serail>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<FindWith_CodeR_SerailResponse xmlns="http://tempuri.org/">
<FindWith_CodeR_SerailResult>string</FindWith_CodeR_SerailResult>
</FindWith_CodeR_SerailResponse>
</soap12:Body>
</soap12:Envelope>
HTTP POST
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.
POST /webservices/findstatus.asmx/FindWith_CodeR_Serail HTTP/1.1
Host: localhost Content-Type: application/x-www-form-urlencoded
Content-Length: length CodeReception=string&Serial=string
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
Now i'm stock on php codes that call this web service with 2 parameter
please send me full code that i can paste it in a php file for test.
no matter what kind of method is used : SOAP or HTTP POST
please help me.
i used this php code and every thing is OK:
<?php
$client = new SoapClient("http://www.MyWebSite.com/webservices/findstatus.asmx?WSDL");
$params=new stdClass();
$params->CodeReception = '11111';
$params->Serial = '22222222';
$result = $client->FindWith_CodeR_Serail($params)->FindWith_CodeR_SerailResult;
echo $result;
?>
<?php
$client = new SoapClient("http://www.MyWebSite.com/webservices/findstatus.asmx?WSDL");
$params=new stdClass();
$params->CodeReception = '11111';
$params->Serial = '22222222';
$result = $client->FindWith_CodeR_Serail($params)->FindWith_CodeR_SerailResult;
echo $result;
?>

accessing SOAP via PHP

I've got a website which needs to send a request to another server and retrieve some data. I don't know anything about SOAP, so I need an expert help here.
Here is the data the second server is giving me.
I dont know where to start and how to do it. So any help is appreciated.
Could you give me a working example of php code which works with this code.
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /Service1.asmx HTTP/1.1
Host: puanreport.retail.az
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/_find"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<_find xmlns="http://tempuri.org/">
<par>string</par>
</_find>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<_findResponse xmlns="http://tempuri.org/">
<_findResult>
<bon>
<Cari_Kod>string</Cari_Kod>
<Puan>string</Puan>
</bon>
<bon>
<Cari_Kod>string</Cari_Kod>
<Puan>string</Puan>
</bon>
</_findResult>
</_findResponse>
</soap:Body>
</soap:Envelope>
The most simple approach would be:
$client = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL');
$result = $client->GetGeoIP(array('IPAddress' => '8.8.8.8'));
print_r($result);
this gives you:
stdClass Object
(
[GetGeoIPResult] => stdClass Object
(
[ReturnCode] => 1
[IP] => 8.8.8.8
[ReturnCodeDetails] => Success
[CountryName] => United States
[CountryCode] => USA
)
)
Now you can simply access the values by invoking
$country = $result->GetGeoIPResult->CountryName;
Already answered here
php.net soap class

INVALID_TYPE when creating salesforce attachment

Bellow is the XML POST and Response i get from the sales force servers.
Im trying to add an attachment to an Account but i keep getting INVALID_TYPE.
Im using NuSoap instead of the SalesForce PHP library because the server i'm working on doesnt have the SOAP extension required.
I have no issue with going in and amending the library to make it work but i dont have a clue whats wrong with the XML to fix the issue. I get query information perfectly fine.
All help and advice appreciated!
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope 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/">
<SOAP-ENV:Header>
<nu2113:SessionHeader xmlns:nu2113="urn:enterprise.soap.sforce.com">
<sessionId>00Di00000{---cutting out for privacy--}UrYmByvpO5yRWIK0Gmy</sessionId>
</nu2113:SessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<create xmlns="urn:enterprise.soap.sforce.com">
<sObject>
<type xsi:type="xsd:string">Attachment</type>
<fieldsToNull>
<elementName xsi:type="xsd:string">fieldsToNull</elementName>
<values xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[5]">
<item xsi:type="xsd:string">OwnerId</item>
<item xsi:type="xsd:string">IsPrivate</item>
<item xsi:type="xsd:string">IsPartnerShared</item>
<item xsi:type="xsd:string">ConnectionSentId</item>
<item xsi:type="xsd:string">BodyLength</item>
</values>
</fieldsToNull>
<Id xsi:nil="true"/>
<ParentId xsi:type="xsd:string">001i000000JG17b</ParentId>
<Name xsi:type="xsd:string">Test document</Name>
<Description xsi:type="xsd:string">Test upload from WIN form</Description>
<ContentType xsi:type="xsd:string">.pdf</ContentType>
<Body xsi:type="xsd:string">hello</Body>
</sObject>
</create>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 100 Continue
HTTP/1.1 500 Server Error
Date: Mon, 13 Jan 2014 15:49:56 GMT
Content-Type: text/xml;charset=UTF-8
Content-Length: 676
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>sf:INVALID_TYPE</faultcode>
<faultstring>INVALID_TYPE: Must send a concrete entity type.</faultstring>
<detail>
<sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">
<sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>
<sf:exceptionMessage>Must send a concrete entity type.</sf:exceptionMessage>
<sf:row>-1</sf:row>
<sf:column>-1</sf:column>
</sf:InvalidSObjectFault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
This line might be the problem:
<ContentType xsi:type="xsd:string">.pdf</ContentType>
that is not a valid content type. try this:
<ContentType xsi:type="xsd:string">application/pdf</ContentType>

soap api with betfair

It's my first time using the SOAP API by BetFair I have created one XML file and one file that will call that file. I am not understanding how can I call this and get an output. I have created the XML file below:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<login xmlns="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<request>
<locationId xmlns="">0</locationId>
<username xmlns="">usrname</username>
<password xmlns="">password</password>
<productId xmlns="">18</productId>
<vendorSoftwareId xmlns="">0</vendorSoftwareId>
</request>
</login>
</soap:Body>
</soap:Envelope>
Now to call this file I have also created one php file to do this.
BetFair has given this link for the login api: https://api.betfair.com/global/v3/BFGlobalService.wsdl
<?php
$get_data = file_get_contents("http://pixelonsell.com/dev2/betfair/login.xml");
$b = html_entity_decode($get_data);
$data= urlencode($b);
print_r($data);
$client = new SoapClient("https://api.betfair.com/global/v3/BFGlobalService.wsdl");
$result = $client->LoginReq($data);
print_r($result);
?>
I don't know why it's not working; can you help me out with this? Thank you in advance.
I would avoid using a dedicated SOAP library; in my experience they often don't work because of inconsistencies in the ways different servers implement the SOAP specification. Use a simple HTTP/HTTPS library instead, with the following headers
SOAPAction: urn:login
Content-Length: #{myContentLength}
Content-Type: text/xml
User-Agent: #{myUserAgent}
and the following payload (assuming you're using the Free API):
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 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">
<SOAP-ENV:Body>
<m:login xmlns:m="https://api.betfair.com/global/v3/BFGlobalService">
<m:request>
<username>#{myUsername}</username>
<password>#{myPassword}</password>
<locationId>0</locationId>
<vendorSoftwareId>0</vendorSoftwareId>
<productId>82</productId>
</m:request>
</m:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It looks to me like you're using the wrong namespace for the login element; should be 'https://api.betfair.com/..' not 'http://www.betfair.com/..'.
Good luck.

how to get quotes with soap 1.2 in php?

I'm a complete noob in XML and SOAP,
Could you give some advice on at least where to start, or some example?
(I'm not begging to write code for me)
Here are the specs:
I just expect to receive two double values. What is an easiest way to do it?
POST /CurrencyConvertor.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<ConversionRate xmlns="http://www.webserviceX.NET/">
<FromCurrency>PHP</FromCurrency>
<ToCurrency>USD or EUR</ToCurrency>
</ConversionRate>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<ConversionRateResponse xmlns="http://www.webserviceX.NET/">
<ConversionRateResult>double</ConversionRateResult>
</ConversionRateResponse>
</soap12:Body>
</soap12:Envelope>
The above specs's origin: http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate
The first block is supposed to be a request, and the other response...
EDIT
Alright, I stopped at a standard PHP class, but I don't quite understand what is being asked for in this __doRequest method:
$client = new SoapClient();
$client->__doRequest ( <<<EOD
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<ConversionRate xmlns="http://www.webserviceX.NET/">
<FromCurrency>PHP</FromCurrency>
<ToCurrency>USD or EUR</ToCurrency>
</ConversionRate>
</soap12:Body>
</soap12:Envelope>
EOD
, "http://www.webservicex.net/CurrencyConvertor.asmx" , $???, $??? );
http://www.php.net/manual/en/soapclient.dorequest.php
What is action, and what should I put as version, I know - a soap version 1.2 but the parameter is int so it cannot be assigned a 1.2 value lol...
EDIT2:
Alright, this is what I've got so far, but it gets me an empty string...
$client = new SoapClient(null, array('location'=>'http://www.webservicex.net/CurrencyConvertor.asmx','uri'=>''));
$client->__doRequest ( <<<EOD
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<ConversionRate xmlns="http://www.webserviceX.NET/">
<FromCurrency>PHP</FromCurrency>
<ToCurrency>USD or EUR</ToCurrency>
</ConversionRate>
</soap12:Body>
</soap12:Envelope>
EOD
, "http://www.webservicex.net/CurrencyConvertor.asmx" , "ConversionRate", 2 );
echo "Response :<br>", htmlentities($client->__getLastResponse());
...I just dont get this 'uri' thing - beyond my understanding. It makes me want to hit my head to the wall.
Basically what you need are two parts.
A SOAPClient class, which solves the communication, knows about the server URL, sends requests and receives responses (which you got in XML in your question) and also triggers #2, which is:
The second part is an XML parser / marshaller, which can convert a request objects (containing fromCurrency and toCurrency) to a correct XML string the server can understand (according to the WSDL) and convert some XML into a response object again using the WSDL. This part is a bit tricky, but I found a lot of documentation for that, search for "SOAP PHP" and you get some examples). These two processes are called marshalling and unmarshalling (to help you find something quicker with Google). Your StockQuote webservice doesn't really provide a WSDL, which is basically a description of all possible operations (in your case just one: GetQuote) and its available objects (in your case only simple types string, which don't have to be defined, since they are WSDL standard)
I haven't done SOAP with PHP, but spent a lot of time with Java+SOAP and can understand how difficult it is. In theory you just send some XML to the server and get some XML back. But the XML sent has to be in the correct format and when you receive a response, you want to convert the response into an object and not deal with some XML string.
For a simple web service like this, you might consider constructing the XML request by hand (simply putting together the XML string) and substr the response to find the requested answer.

Categories