PHP call to local .NET web service - php

I'm doing all of this locally for testing purposes right now. I ran the service project in visual studio and have my local version of the site setup to make the call to the web service but it won't hit it.
Here's the call:
$client = new SoapClient(null, array('location' => "https://localhost:51063/Service1.asmx", 'uri' => 'http://localhost:51063/'));
$client->newMeeting(array('id' => '10000', 'location' => 'test', 'committee' => 'test', 'desc' => 'test', 'date' => '2011-08-01', 'duration' => '180', 'agenda' => '', 'notes' => '', 'agenda' => '', 'notes' => ''));
And using that I get this error:
Uncaught SoapFault
Could not connect to host
Trace in execution order:
Dispatcher→dispatch(null, 'page') on line 98 in C:\xampp\htdocs\narca\admin\index.php
Dispatcher→executeAction('plugin', 'committees', array[1]) on line 162 in C:\xampp\htdocs\narca\frog\Framework.php
PluginController→execute('committees', array[1]) on line 247 in C:\xampp\htdocs\narca\frog\Framework.php
call_user_func_array(array[2], array[0]) on line 84 in C:\xampp\htdocs\narca\frog\app\controllers\PluginController.php
CommitteesController→addevent() on line unknown in unknown
SoapClient→newMeeting(array[8]) on line 429 in C:\xampp\htdocs\narca\frog\plugins\committees\CommitteesController.php
SoapClient→__call('newMeeting', array[1]) on line unknown in unknown
SoapClient→__doRequest('<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:...', 'https://localhost:51063/Service1.asmx', 'http://localhost:51063/#newMeeting', 1, 0) on line unknown in unknown
If I try to call it like this:
$client = new SoapClient("https://localhost:51063/Service1.asmx?WSDL");
I get a different error:
Uncaught SoapFault
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://97.67.111.2:51063/Service1.asmx?WSDL' : failed to load external entity "http://97.67.111.2:51063/Service1.asmx?WSDL"
Trace in execution order:
Dispatcher→dispatch(null, 'page') on line 98 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/admin/index.php
Dispatcher→executeAction('plugin', 'committees', array[1]) on line 162 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/Framework.php
PluginController→execute('committees', array[1]) on line 247 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/Framework.php
call_user_func_array(array[2], array[0]) on line 84 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/app/controllers/PluginController.php
CommitteesController→addevent() on line unknown in unknown
SoapClient→SoapClient('http://97.67.111.2:51063/Service1.asmx?WSDL') on line 423 in /mnt/stor2-wc1-dfw1/410993/410996/lab.narca.org/web/content/frog/plugins/committees/CommitteesController.php
Is this setup even possible? Or is there a way I can make the live site hit my local service?

Can you fetch that URL from the server PHP is on, using curl or something similar? Is there a firewall somewhere that blocks those high-numbered-post requests? Your PHP looks fine so I don't think you are doing anything wrong there.

Related

Phpunit testing, error when including file

Very new to php unit and can't exactly work out whats wrong. My class is as follows:
<?php
include $_SERVER['DOCUMENT_ROOT'] . '/assets/php/global_php_includes.php';
use PHPUnit\Framework\TestCase;
final class PesticideTests extends TestCase {
public function addPesticideTest() {
$data = array(
"code" => randomString(16),
"created_by" => $_SESSION['userCode'],
"company_code" => "TEST_COMPANY",
"crop_code" => "TEST_CROP",
"content" => "TEST_CONTENT",
"comments" => "TEST_COMMENTS",
"function" => "TEST_FUNCTION",
"pcs_no" => 0123,
"phi" => "TEST_PHI",
"product_name" => "TEST_PRODUCT",
"substance" => "TEST_SUBSTANCE",
"date_of_reg_review" => "01-01-0001",
"use_by_date" => "01-01-0001",
"off_label_approval" => "TEST_OFF_LABEL_APPROVED",
"latest_time_of_application" => "TEST_LATEST_TIME_OF_APPLICATION",
"max_individual_dose" => "TEST_MAX_INDIVIDUAL_DOSE",
"max_total_dose" => "TEST_MAX_TOTAL_DOSE",
"max_no_applications" => "TEST_MAX_NO_APPLICATIONS",
"method_of_application" => "TEST_METHOD_OF_APPLICATION",
"status" => 'inactive'
);
$result = addPesticide($connection, $data);
$this->assertEquals(1, $result);
}
}
the command I run to test it is ./vendor/bin/phpunit tests/PesticideTests.php
and the error I get is
PHP Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(/assets/php/global_php_includes.php): failed to open stream: No such file or directory in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHP Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
Warning: include(): Failed opening '/assets/php/global_php_includes.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\tapp\tests\PesticideTests.php on line 3
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 00:00.014, Memory: 4.00 MB
There was 1 warning:
1) Warning
No tests found in class "PesticideTests".
WARNINGS!
Anyone have any idea what I'm doing wrong? If I also run it as just ./vendor/bin/phpunit tests then I get the error "No tests found". Pretty confused
EDIT:
I have fixed the test not being found by naming it by the wrong convention, still getting an error for the include file
When running your code withing phpunit there is no $_SERVER['DOCUMENT_ROOT'] set. This only gets set when running in the context of a webserver. Just replace this with the directory where the assets directory is.

Failed to load external entity

I am trying to integrate fedex API and getting this error .
Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "../wsdl/RateService_v13.wsdl" in test.php on line 12
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '../wsdl/RateService_v13.wsdl' in D:\wamp\www\fedexapi\AddressValidationService_v4_php\php\AddressValidationWebServiceClient\rate_test.php:12 Stack trace: #0 D:\wamp\www\fedexapi\AddressValidationService_v4_php\php\AddressValidationWebServiceClient\rate_test.php(12): SoapClient->SoapClient('../wsdl/RateSer...', Array) #1 {main} thrown in test.php on line 12
<?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 2.0.0
require_once('../library/fedex-common.php5');
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "../wsdl/LocationsService_v3.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
'ParentCredential' => array(
'Key' => getProperty('parentkey'),
'Password' => getProperty('parentpassword')
),
'UserCredential' => array(
'Key' => getProperty('key'),
'Password' => getProperty('password')
)
);
?>
How to solve this ?
Afaik the SoapClient first aprameter need to be an URI, not a local filename on your disk.
The error indicated that it was unable to load the wsdl.
Have a look at the specs and this expample should make it clear.
Relative path works as well.
In my case, I had to fix the wsdl file's relative path.

soap parsing unexpected in complextype

I can parse the .WSDL file and call the functions using soapUI, but not
using PHP5. It has also been shown to work with JAVA/AXIS and .NET.
I need the WSDL caching functionality of the PHP5 SOAP procedures
otherwise I might stick with soapUI.
Reproduce code:
$optional = array
(
'trace' => 1,
'exceptions' => true,
'soap_version' => SOAP_1_1,
'encoding' => 'ISO-8859-1'
);
$wsdl = 'https://www-a.audanet.de/b2b/services/AXAttachmentService?wsdl';
$client = new SoapClientAuth($wsdl, $optional);
Expected result:
A useable instance of a SoapClient object.
Actual result:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing Schema: unexpected 'attribute' in complexType in ../class/SoapClientAuth.php:62
Stack trace:
0 ../class/SoapClientAuth.php(62): SoapClient->SoapClient('https://www-a.a...', Array)
1 ../class/Ws.php(30): SoapClientAuth->SoapClientAuth('https://www-a.a...', Array)
2 ../zalacz.php(468): Ws->podlaczenieWS()
3 {main}
thrown in ../class/SoapClientAuth.php on line 62

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'source' property in

I am trying to connect osticket support system with opencart.
I tried to integrate with this SOAP
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$osticket = new SoapClient('http://www.website.com/osticket/api/soap/index.php?wsdl');
// Set up the parameters
$args = array(
'username' => 'WebService',
'password' => 'MySecr3tp#ssword',
'origin' => 'Web',
'alertUser' => true,
'alertStaff' => true,
'ticketData' => array(
'name' => utf8_encode('sir Test'),
'email' => utf8_encode('some#email.com'),
'subject' => utf8_encode('testing'),
'message' => utf8_encode('this is a message'),
'topicId' => 3, //topic Website Support
'deptId' => 2, //department Sales
'staffId' => null,
'duedate' => null,
'time' => null,
'pri' => 2, // default priority
'phone' => null,
)
);
try {
// Send the request and receive the ticketID
$result = $osticket->__call('ostTicket.open',$args);
}
catch (SoapFault $e) {
throw $e;
}
?>
The error I get is
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'source' property in /home/website/website.com/catalog/view/theme/testtheme/template/information/contact.tpl:60
Stack trace:
#0 /home/website/website.com/catalog/view/theme/testtheme/template/information/contact.tpl(60): SoapClient->__call('ostTicket.open', Array)
#1 /home/website/website.com/vqmod/vqcache/vq2-system_engine_controller.php(67): require('/home/website/tu...')
#2 /home/website/website.com/catalog/controller/information/contact.php(127): Controller->render()
#3 /home/website/website.com/vqmod/vqcache/vq2-system_engine_front.php(43): ControllerInformationContact->index()
#4 /home/website/website.com/vqmod/vqcache/vq2-system_engine_front.php(29): Front->execute(Array, Array)
#5 /home/website/website.com/index.php(238): Front->dispatch(Object(Action))
#6 {main} thrown in/home/website/website.com/catalog/view/theme/testtheme/template/information/contact.tpl on line 60
Here is the line 60 (/template/information/contact.tpl):
$result = $osticket->__call('ostTicket.open',$args);
I'd be grateful if anyone kindly help me in this issue.
SOAP Info
This is from phpinfo
Soap Client enabled
Soap Server enabled
Directive Local Value Master Value
soap.wsdl_cache 1 1
soap.wsdl_cache_dir /tmp /tmp
soap.wsdl_cache_enabled 1 1
soap.wsdl_cache_limit 5 5
soap.wsdl_cache_ttl 86400 86400
I'm also having same problem, and I've been searching the web and found no answer. So, I traced it myself. And I loved to share how I fixed it.
As you can see on the http://www.website.com/osticket/api/soap/index.php?wsdl (change it to your URL)
under the ( xsd:complexType name="TicketData" ),which parameters needed for ostTicket.open
you can see that there's an element (xsd:element name="source" type="xsd:string") named source, so that's what is missing on the ticketData array. Just add that inside your ticketData array, can be assigned w/ null.
ex. 'source' => null,
This solved my problem. Hope it helps.

How to change the namespace sent with a SOAP request?

Related to this question: How to request an answer from a SOAP XML API?
I have this PHP script sending the request with the required fields:
$client = new SoapClient('https://live.domainbox.net/?WSDL');
$params = array(
'AuthenticationParameters' => array(
'Reseller' => 'resellername',
'Username' => 'myusername',
'Password' => 'mypassword'
),
'CommandParameters' => array(
'DomainName' => 'mydomain.com',
'LaunchPhase' => 'GA'
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);
I get the following error message:
Fatal error: Uncaught SoapFault exception: [soap:VersionMismatch]
Possible SOAP version mismatch: Envelope namespace
http://schemas.xmlsoap.org/soap/envelope/ was unexpected.
Expecting http://www.w3.org/2003/05/soap-envelope. in
/home/nosa/public_html/dev/check-domain-availability.php:20 Stack
trace: #0
/home/nosa/public_html/dev/check-domain-availability.php(20):
SoapClient->__call('CheckDomainAvai...', Array) #1
/home/nosa/public_html/dev/check-domain-availability.php(20):
SoapClient->CheckDomainAvailability(Array) #2 {main} thrown in
/home/nosa/public_html/dev/check-domain-availability.php on line 20
I removed and recompiled apache to include the latest SOAP version available using WHM/cPanel.
My question is:
How do I send the correct envelope namespace?
When building your soap_client object, you can pass an option's array, by default, the version will be 1.1 as per php documentation.
The error you have seems to point out that the service might be SOAP 1.2 so you need to set it to 1.2...
$client = new SoapClient('https://live.domainbox.net/?WSDL', array('soap_version' => SOAP_1_2));
Try that out!

Categories