PHP에서 웹 서비스를 쉽게 사용하는 방법
-
08-06-2019 - |
해결책
나는 큰 성공을 거두었습니다. wsdl2php.웹 서비스에 사용되는 모든 객체와 메소드에 대한 래퍼 클래스를 자동으로 생성합니다.
다른 팁
PHP 5에서는 다음을 사용할 수 있습니다. 비누클라이언트 WSDL에서 웹 서비스 기능을 호출합니다. 예를 들어:
$client = new SoapClient("some.wsdl");
$client는 이제 some.wsdl에 정의된 클래스 메소드를 갖는 객체입니다.따라서 WSDL에 getTime이라는 메소드가 있는 경우 다음을 호출하면 됩니다.
$result = $client->getTime();
그리고 그 결과는 (분명히) $result 변수에 있을 것입니다.__getFunctions 메서드를 사용하면 사용 가능한 모든 메서드 목록을 반환할 수 있습니다.
나는 사용했다 NuSOAP 과거에.포함할 수 있는 PHP 파일 세트이기 때문에 마음에 들었습니다.웹 서버에 설치할 것이 없으며 변경할 구성 옵션도 없습니다.보너스인 WSDL 지원도 있습니다.
이것 기사 PHP SoapClient를 사용하여 API 웹 서비스를 호출하는 방법을 설명합니다.
음, 이러한 기능은 해당 언어 개발에 사용하는 도구에만 적용됩니다.
예를 들어 메모장을 사용하여 코드를 작성하는 경우 이러한 도구가 없을 것입니다.따라서 사용 중인 도구에 대해 질문해야 할 수도 있습니다.
PHP의 경우: http://webservices.xml.com/pub/a/ws/2004/03/24/phpws.html
안녕하세요. 저는 다음 사이트에서 이것을 얻었습니다: http://forums.asp.net/t/887892.aspx?Consume+an+ASP+NET+Web+Service+with+PHP
웹 서비스에는 메소드가 있습니다 Add
두 개의 매개변수를 사용합니다.
<?php
$client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl");
print_r( $client->Add(array("a" => "5", "b" =>"2")));
?>
다음을 제공받았다고 가정해 보겠습니다.
<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>
그리고
<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>
액세스한다고 가정 해 보겠습니다. http://thesite.com/ WSDL 주소는 다음과 같습니다.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;
}
보시다시피 XML에 지정된 항목은 LoginId 값이 변경될 수 있지만 PHP 코드에서 사용됩니다.