如何使用wsHTTPBinding创建php soap wsdl客户端


How to create php soap wsdl client with wsHTTPBinding?

我正在尝试从wsdl制作php客户端,该客户端使用WCF服务。我已经设法通过仅传递凭据(不需要pem认证)来使用c#控制台应用程序的web服务。

wsdl的url如下(它是一个测试环境):

https://extenavigator.ukho.gov.uk/serviceB2B/submitUKHOOrdering.svc?wsdl

因此,如果有人想尝试创建soap客户端,请使用此wsdl.

"尝试使用缺乏相关服务权限的帐户访问将导致带有ProcessResult的响应。失败确认和消息添加到Messages属性:服务[serviceName]对用户[userId]不可用"(来自提供者)。

因此,具有错误凭据的工作soap客户机应该返回上述消息。

为了在php中创建soap客户端,我首先通过wsdl2phpgenerator创建了存根类。然后我实例化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));

其中OrderingService是扩展SOAP客户端类的存根类。

最后我调用这样一个方法:

$getHoldingsRequest = new GetHoldingRequest(DIST_ID, 25555, ProductType::AVCSCharts); // set some params for the called method
$responce = $orderServiceClient->GetHoldings($getHoldingsRequest); // call the method

我得到的错误是:错误获取http头

我已经在php.ini和apache conf文件中启用了ssl。我用的是windows电脑。

我读过这篇文章:

使用PHP连接Web服务

SoapFault exception: [HTTP] Error取回HTTP headers

我发现问题是soap头必须自定义,以便通过凭据("SSL上的用户名和密码身份验证")

我也尝试过创建自定义soap头:

 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);
    }
}

 $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));
最后

$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>";

:

获取http报头错误

我也尝试了上面提到的其他事情,但没有结果。

从上面提到的帖子:

"但是正如我上面所说的:我认为需要更多关于WS-Security规范和给定服务体系结构的知识才能使其工作。"

所以如果有人有soap客户端的经验,并且能够为这个wsdl创建一个php客户端,这将是一个很大的帮助。

对于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();

我是新来的,不确定我的帖子是否有帮助,但我会尽量帮助你-如果你已经得到了你的WSDL文件或URL,那么

-你可以使用php SoapClient

  • 请忽略,如果帖子不符合您的要求
尝试遵循下面给出的示例以及您的WSDL文件结构(hold)函数和参数(XML)

这取决于你,可以把第一步和第二步的代码放在类/函数中,或者可以用简单的给定方式使用

步骤1-

试{

$client = new SoapClient(SOAP_CLIENT_WSDL_URL, array('soap_version' => soap_version, 'trace' => true));返回客户端美元;

} catch (SoapFault $fault) {

trigger_error("SOAP故障:(faultcode: {$ Fault ->faultcode}, faultstring: {$ Fault ->faultstring})", E_USER_ERROR);

die ();

}

步骤2 -

result = $client->your_wsdl_containing_function("follow_wsdl_parameter")

$xml_last_response = $client->__getLastResponse();

回声";print_r ($ xml_last_response);