[英]How to create php soap wsdl client with wsHTTPBinding?
I am trying to make a php client from a wsdl, that consumes a WCF service. 我正在尝试从wsdl中创建一个PHP客户端,该客户端使用WCF服务。 I have managed to consume the web service with a C# console application by only passing the credentials(no pem certification needed).
我已经通过仅通过凭据(不需要pem认证)来使用C#控制台应用程序使用了Web服务。
The url for the wsdl is the following(it is a test environment): wsdl的网址如下(它是一个测试环境):
https://extenavigator.ukho.gov.uk/serviceB2B/submitUKHOOrdering.svc?wsdl
So If someone wants to try to create a soap client use this wsdl. 因此,如果有人想创建一个肥皂客户端,请使用此wsdl。
"Attempting to access with an account that is lacking the relevant service permission will result in a response with a ProcessResult.Failure Acknowledgement and a Message added to the Messages property of: The service [serviceName] is not available to the user [userId]" (from the provider). “尝试使用缺少相关服务权限的帐户进行访问将导致响应并显示ProcessResult.Failure确认,并且向以下消息的Messages属性添加了一条消息:服务[serviceName]对用户[userId]不可用” (来自提供商)。
So a working soap client with wrong credentials should return the above message. 因此,工作肥皂客户端使用错误的凭据应返回上述消息。
In order to create a soap client in php first I created the stub classes via wsdl2phpgenerator. 为了在php中创建肥皂客户端,我首先通过wsdl2phpgenerator创建了存根类。 Then I instantiate the soap client as below:
然后我实例化soap客户端,如下所示:
ini_set('max_execution_time', 480);
ini_set('default_socket_timeout', 400);
$orderServiceClient = new OrderingService(array('login' => DIST_B2B_USERNAME, 'password' => DIST_B2B_PASSWORD, "trace"=>1,
"exceptions"=>1, 'cache_wsdl' => WSDL_CACHE_MEMORY, 'soap_version' => SOAP_1_2, 'keep_alive' => false,
"connection_timeout" => 240, 'verifypeer' => false, 'verifyhost' => false, "ssl_method" => SOAP_SSL_METHOD_TLS));
where OrderingService is the stub class that extends SOAP client class. 其中,OrderingService是扩展SOAP客户端类的存根类。
At last I call a method like this: 最后,我调用这样的方法:
$getHoldingsRequest = new GetHoldingRequest(DIST_ID, 25555, ProductType::AVCSCharts); // set some params for the called method
$responce = $orderServiceClient->GetHoldings($getHoldingsRequest); // call the method
The error I get is: Error Fetching http headers 我得到的错误是:提取HTTP标头时出错
I have enabled ssl in php.ini and in the apache conf file. 我已经在php.ini和apache conf文件中启用了ssl。 I am using a windows PC.
我正在使用Windows PC。
I have read this posts: 我已阅读以下帖子:
Connecting to WS-Security protected Web Service with PHP 使用PHP连接到受WS-Security保护的Web服务
SoapFault exception: [HTTP] Error Fetching http headers SoapFault异常:[HTTP]提取HTTP标头时出错
I figure out that the problem is that the soap header must be customized in order to pass the credentials ("Username and Password authentication over SSL") 我发现问题是必须自定义soap标头才能传递凭据(“通过SSL的用户名和密码身份验证”)
I have also tried to create custom soap headers: 我也尝试创建自定义的肥皂标题:
class WsseAuthHeader extends SoapHeader
{
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
function __construct($user, $pass, $ns = null)
{
if ($ns)
{
$this->wss_ns = $ns;
}
$auth = new stdClass();
$auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
$security_sv = new SoapVar(
new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
}
and 和
$wsse_header = new WsseAuthHeader("xxxx", "xxxx");
$orderServiceClient = new OrderingService(array('trace' => true, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_MEMORY,
'soap_version' => SOAP_1_2, 'keep_alive' => false, 'connection_timeout' => 240));
$orderServiceClient->__setSoapHeaders(array($wsse_header));
Finally 最后
$getHoldingsRequest = new GetHoldingRequest(DIST_ID, 25555, ProductType::AVCSCharts);
$getHoldingsRequest->setRequestId($GUID);
try {
$responce = $orderServiceClient->GetHoldings($getHoldingsRequest);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "<pre>" . var_export($orderServiceClient->__getLastRequest(), TRUE) . "</pre>";
I get: 我得到:
Error Fetching http headers 提取HTTP标头时出错
NULL 空值
I have also tried other things mentioned in the above posts with no result. 我也尝试了以上帖子中提到的其他操作,但没有结果。
From the posts mentioned above: 从上面提到的帖子中:
"But as I said above: I think that much more knowledge about the WS-Security specification and the given service architecture is needed to get this working." “但是正如我上面所说:我认为需要更多有关WS-Security规范和给定服务体系结构的知识才能使此工作正常进行。”
So if someone has experience with soap client and is able to create a php client for this wsdl that would be a great help. 因此,如果某人有使用肥皂客户端的经验,并且能够为此wsdl创建php客户端,那将是很大的帮助。
For GUID I used the following function: 对于GUID,我使用了以下功能:
function getGUID(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
$GUID = getGUID();
I am new and not sure my post will be helpful or not but I will try to help you - If you have already got your WSDL file or URL then 我是新手,不确定我的文章会不会对您有帮助,但是我会尽力帮助您-如果您已经有了WSDL文件或URL,那么
-you can use php SoapClient -您可以使用php SoapClient
Try to follow example give below and also your WSDL file structure(holding function and parameter via XML) 尝试遵循下面的示例以及您的WSDL文件结构(通过XML保留函数和参数)
Its up to you, can put step 1 and step 2 code inside class/function, or can use in simple given way. 它由您决定,可以将第1步和第2步代码放入类/函数中,或者可以以简单的给定方式使用。
Step 1- 第1步-
try { 尝试{
$client = new SoapClient(SOAP_CLIENT_WSDL_URL, array('soap_version' => SOAP_VERSION, 'trace' => true)); $ client = new SoapClient(SOAP_CLIENT_WSDL_URL,array('soap_version'=> SOAP_VERSION,'trace'=> true)); return $client;
返回$ client;
} catch (SoapFault $fault) { }捕获(SoapFault $ fault){
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR); trigger_error(“ SOAP错误:(错误代码:{$ fault-> faultcode},错误字符串:{$ fault-> faultstring})”,E_USER_ERROR);
die(); 死();
} }
Step 2- 第2步-
result = $client->your_wsdl_containing_function("follow_wsdl_parameter") 结果= $ client-> your_wsdl_ contains_function(“ follow_wsdl_parameter”)
$xml_last_response = $client->__getLastResponse(); $ xml_last_response = $ client-> __ getLastResponse();
echo '';print_r($xml_last_response); 回声''; print_r($ xml_last_response);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.