I have a .net web service which provide multiple methods and public classes.
I want to use these classes in php.
How can I do it?
this is my web service: http://10.2.3.74/AdaptorRepeater/BillPatientService.asmx?WSDL
for example I want access to AdmissionVO class and its properties
$client = new soapclient('http://10.2.3.74/AdaptorRepeater/BillPatientService.asmx?WSDL');
$header = new SoapHeader('http://sepas.behdasht.gov.ir/','HeaderMessageVO',$HeaderMessageVO,false);
$client->__setSoapHeaders($header);
$send = $client->SavePatientBillSecure($params);
I want for example this :
$client->AdmissionVO->MedicalRecordNumber = '1234';
Using SOAP Call You can access any Dot.Net Web service
You need to have Dot net web service WSDL path
now
<?php
//turn off WSDP caching if not in a production environment
$ini = ini_set("soap.wsdl_cache_enabled","0");
//instantiate the SOAP client
$client = new SoapClient("http://example.com/dotnet.asmx?WSDL");
echo $client->GetAllContactNames()->GetAllContactNamesResult;
//...optional additional code goes here...
?>
Related
Trying to make a call to the below web service, is this the correct way to pass a token in the soap header, its returning an incorrect token response, but the token is correct when i use it with soap ui..?
$soapclient = new SoapClient('http://api.fm-
web.co.za/webservices/AssetDataWebSvc/DriverProcessesWS.asmx?WSDL');
$token = array('Token'=>'XXXXXX');
$header = new SoapHeader('ass','soapenv',$token,false);
$response = $soapclient->__soapCall('GetDriverList',array(''),NULL,$header);
var_dump($response);
after some messing around this worked.
$soapclient = new SoapClient('http://api.fm-
web.co.za/webservices/AssetDataWebSvc/DriverProcessesWS.asmx?WSDL');
//$token = array('Token'=>'XXXXXX');
$header = new
SoapHeader('http://www.omnibridge.com/SDKWebServices/AssetData',
'TokenHeader',array('Token'=>'XXXXXX'),false);
//$DriverID = 3;
$params = array('DriverID'=>'3');
$response = $soapclient-
>__soapCall('GetDriver',array($params),NULL,$header);
var_dump($response);
SoapHeader definition can be tricky especially if you're not familiar with SOAP.
My advise would be to use a WSDL to PHP generator that would provide you a SDK with the method to set any SoapHeader and particularly this SoapHeader.
You should try the PackageGenerator project which should provide you the SoapHeader methods within the ServiceType\Get instance you'll have to create. Take a look to the generated tutorial.php file.
I'm trying to configure the google-api-php-client library in my project.
I've already created a custom google app engine project that consists in a cloud endpoint. The project is called 'set-core', the service is called 'vrp API', version 'v1' and the method vrp.vrp.getSolution().
Now in my PHP code i'm following this example:
https://developers.google.com/api-client-library/php/start/get_started#building-and-calling-a-service
The problem is that in this example there's no mention how to connect to any custom service, outside Google's ones.
My PHP code is:
$client = new Google_Client();
$client->setApplicationName("set-core");
$client->setDeveloperKey("AIzaSyByd8cRJNGYC4szFLbr3**************");
$client->isAppEngine(true);
$service = new Google_Service_Appengine_Service($client);
$results = $service->vrp->vrp.vrp.getSolution($stringVehicles, $stringServices, $stringDepot);
Unfortunately, on the last line, PHP warns me:
Notice: Trying to get property of non-object (I assume it's $service).
The problem is that I don't really know how to set up all the client's params and which Service type use.
You are going to want to create an authorized HTTP client and then request your API endpoint directly with it. The AppEngine service classes you're manipulating above are not meant for this use case. Something like this should work:
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$httpClient = $client->authorize();
$response = $httpClient->request('GET', 'https://myapp.appspot.com/vrp/getSolution');
The $httpClient class is an instance of GuzzleHttp\Client, but with your Google authentication already added to it. See the documentation for making a request with Guzzle.
I hope this helps!
Is there any way to call an EJB session bean from PHP? Are there any specific functions to do that?
Not really. If you can make CORBA calls, most container support CORBA as a protocol to talk to a remote EJB, but I wouldn't recommend it.
You'd have better luck exposing the EJB Session Bean call as a SOAP Web Service, or simply facade it with a Servlet and invoke that as an ad hoc web service.
Now, if you're running PHP within a Java EE server (Resin I believe can run PHP), then you might be able to invoke a Java call that can call an EJB Method.
But, frankly, the web service or ad hoc web facade is likely your best, and quickest path to success, assuming you're allowed to write them.
There are some libraries that do Java/Php bridge implementation, such as PHP/Java Bridge.
So if you were using IBM WebSphere (source):
<?php
// Get the provider URL and Initial naming factory
// These properties were set in the script that started the Java Bridge
$system = new Java("java.lang.System");
$providerUrl = $system->getProperty("java.naming.provider.url");
$namingFactory = $system->getProperty("java.naming.factory.initial");
$envt = array(
"javax.naming.Context.PROVIDER_URL" => $providerUrl,
"javax.naming.Context.INITIAL_CONTEXT_FACTORY" => $namingFactory,);
// Get the Initial Context
$ctx = new Java("javax.naming.InitialContext", $envt);
// Find the EJB
$obj = $ctx->lookup("WSsamples/BasicCalculator");
// Get the Home for the EJB
$rmi = new Java("javax.rmi.PortableRemoteObject");
$home = $rmi->narrow($obj, new Java("com.ibm.websphere.samples.technologysamples.ejb.stateless.basiccalculatorejb.BasicCalculatorHome"));
// Create the Object
$calc = $home->create();
// Call the EJB
$num = $calc->makeSum(1,3);
print ("<p> 1 + 3 = $num </p>");
?>
I'm extremely new to SOAP and I'm trying to implement a quick test client in PHP that consumes a ASP.NET web service. The web service relies on a Soap Header that contains authorization parameters.
Is it possible to send the auth header along with a soap request when using WSDL?
My code:
php
$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL");
$service->AddPendingUsers($users, 3); // Example
webservice
[SoapHeader("AuthorisationHeader")]
[WebMethod]
public void AddPendingUsers(List<PendingUser> users, int templateUserId)
{
ateamService.AddPendingUsers(users, templateUserId, AuthorisationHeader.UserId);
}
How would the auth header be passed in this context? Or will I need to do a low lever __soapCall() to pass in the header? Also, am I invoking the correct soap call within PHP?
You should be able to create a header and then add it to the client so it is sent for all subsequent requests. You will probably need to change the namespace parameter.
$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL");
// Namespace Header Name value must-understand
$header = new SoapHeader('http://tempuri.org/', 'AuthorisationHeader', $value, false);
$service->__setSoapHeaders(array($header));
$service->AddPendingUsers($users, 3); // Example
More information here
$client = new SoapClient(PassportWebService);
$apiauth =array('userName'=>HeaderName,'password'=>HeaderPassport,'ip'=>$onlineip);
$authvalues = new SoapVar($apiauth, SOAP_ENC_OBJECT,'ReqHeader',"SoapBaseNameSpace");
$header = new SoapHeader("SoapBaseNameSpace","ReqHeader", $authvalues, true);
$client->__setSoapHeaders(array($header));
Is there available any tool for PHP which can be used to generate code for consuming a web service based on its WSDL? Something comparable to clicking "Add Web Reference" in Visual Studio or the Eclipse plugin which does the same thing for Java.
In PHP 5 you can use SoapClient on the WSDL to call the web service functions. For example:
$client = new SoapClient("some.wsdl");
and $client is now an object which has class methods as defined in some.wsdl. So if there was a method called getTime in the WSDL then you would just call:
$result = $client->getTime();
And the result of that would (obviously) be in the $result variable. You can use the __getFunctions method to return a list of all the available methods.
I've had great success with wsdl2php. It will automatically create wrapper classes for all objects and methods used in your web service.
I have used NuSOAP in the past. I liked it because it is just a set of PHP files that you can include. There is nothing to install on the web server and no config options to change. It has WSDL support as well which is a bonus.
This article explains how you can use PHP SoapClient to call a api web service.
Say you were provided the following:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://thesite.com/">
<x:Header/>
<x:Body>
<int:authenticateLogin>
<int:LoginId>12345</int:LoginId>
</int:authenticateLogin>
</x:Body>
</x:Envelope>
and
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<authenticateLoginResponse xmlns="http://thesite.com/">
<authenticateLoginResult>
<RequestStatus>true</RequestStatus>
<UserName>003p0000006XKX3AAO</UserName>
<BearerToken>Abcdef1234567890</BearerToken>
</authenticateLoginResult>
</authenticateLoginResponse>
</s:Body>
</s:Envelope>
Let's say that accessing http://thesite.com/ said that the WSDL address is:
http://thesite.com/PortalIntegratorService.svc?wsdl
$client = new SoapClient('http://thesite.com/PortalIntegratorService.svc?wsdl');
$result = $client->authenticateLogin(array('LoginId' => 12345));
if (!empty($result->authenticateLoginResult->RequestStatus)
&& !empty($result->authenticateLoginResult->UserName)) {
echo 'The username is: '.$result->authenticateLoginResult->UserName;
}
As you can see, the items specified in the XML are used in the PHP code though the LoginId value can be changed.
Well, those features are specific to a tool that you are using for development in those languages.
You wouldn't have those tools if (for example) you were using notepad to write code. So, maybe you should ask the question for the tool you are using.
For PHP: http://webservices.xml.com/pub/a/ws/2004/03/24/phpws.html
HI I got this from this site : http://forums.asp.net/t/887892.aspx?Consume+an+ASP+NET+Web+Service+with+PHP
The web service has method Add which takes two params:
<?php
$client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl");
print_r( $client->Add(array("a" => "5", "b" =>"2")));
?>