这个WSDL定义了什么样的SOAP,以及如何使用PHP来使用它?

时间:2014-04-07 01:06:46

标签: php soap wsdl ws-security

我们有一个需要连接到这个SOAP Web服务的PHP应用程序 - 这里是WSDL:https://arixss.arifleet.com/QA/DriveAwayWS/DriveAwaySrvc.svc?wsdl

供应商声称它使用“WS-Security(wsHttpBinding)”。这对我来说意义不大,因为我没有“普通”未经验证的SOAP之外的经验。此外,我知道可能有几种方法来实现WS-Security,并且供应商没有提供完整的规范。

到目前为止,由于this answer中给出的WSSoap类,我已经能够成功连接,验证和运行GetAllRequests方法。但是,我在尝试运行GetRequestDetail方法时遇到困难,因为我不知道要使用哪种参数参数。供应商提供此代码片段作为示例:

DriveAwayClient client = new DriveAwayClient();
client.ClientCredentials.UserName.UserName = "…";
client.ClientCredentials.UserName.Password = "…";
ARIRqst rqst = new ARIRqst();
rqst.RqstType = "ORDER";
rqst.OrderID = "12345";
string RequestDetail;
RequestDetail = client.GetRequestDetail(rqst);

此代码无法在PHP中重写(至少使用WSSoap类),因为我无法使用WSSoap注入ARIRqst对象。此外,我不知道如何实例化ARIRqst对象,因为我无法访问PHP中的ARIRqst()类。

我想如果我更了解这个Web服务的具体要求,正如WSDL所定义的那样 - 它的具体类型是什么,以及使用了什么身份验证 - 我会更幸运地在PHP中找到一个可以使用它的例子,或至少找到规范,以便我可以编写自己的实现。

更新:具体而言,我最终只需要知道如何格式化此Web服务的GetRequestDetail方法的请求。这是我发送的内容:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://tempuri.org/">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://tempuri.org/IDriveAway/GetRequestDetail</a:Action>
        <a:MessageID>urn:uuid:eacedde2-cec5-4da1-afbf-822fe2e92793</a:MessageID>
        <a:ReplyTo>
            <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
        </a:ReplyTo>
        <a:To s:mustUnderstand="1">https://arixss.arifleet.com/QA/DriveAwayWS/DriveAwaySrvc.svc?wsdl</a:To>
        <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
            <u:Timestamp u:Id="_0">
                <u:Created>2014-04-08T23:20:00Z</u:Created>
                <u:Expires>2014-04-08T23:25:00Z</u:Expires>
            </u:Timestamp>
            <c:SecurityContextToken xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc" u:Id="uuid-85c09ef0-83e1-417c-b9c7-5892798ee739-197">
                <c:Identifier>urn:uuid:24d56285-84f1-4c74-8093-5f72090ab92f</c:Identifier>
            </c:SecurityContextToken>
            <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
                <SignedInfo>
                    <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"/>
                    <Reference URI="#_0">
                        <Transforms>
                            <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                        </Transforms>
                        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                        <DigestValue>[REDACTED]</DigestValue>
                    </Reference>
                </SignedInfo>
                <SignatureValue>[REDACTED]</SignatureValue>
                <KeyInfo>
                    <o:SecurityTokenReference>
                        <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" URI="#uuid-85c09ef0-83e1-417c-b9c7-5892798ee739-197"/>
                    </o:SecurityTokenReference>
                </KeyInfo>
            </Signature>
        </o:Security>
    </s:Header>
    <s:Body>
        <ns1:GetRequestDetail xsi:type="ns1:ARIRqst">
            <RqstType>ORDER</RqstType>
            <RqstID>1234</RqstID>
            <OrderID>1234-1</OrderID>
            <QuoteID>1</QuoteID>
        </ns1:GetRequestDetail>
    </s:Body>
</s:Envelope>

这是来自服务器的响应,包含InternalServiceFault“未设置为对象实例的对象引用”(我假设这意味着我没有正确编码ARIRqst对象在请求中):

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
        <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action>
        <a:RelatesTo>urn:uuid:c0af2ed0-9afb-4c77-a09f-2463bf5cbc52</a:RelatesTo>
        <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
            <u:Timestamp u:Id="_0">
                <u:Created>2014-04-08T23:20:26.872Z</u:Created>
                <u:Expires>2014-04-08T23:25:26.872Z</u:Expires>
            </u:Timestamp>
        </o:Security>
    </s:Header>
    <s:Body>
        <s:Fault>
            <s:Code>
                <s:Value>s:Receiver</s:Value>
                <s:Subcode>
                    <s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</s:Value>
                </s:Subcode>
            </s:Code>
            <s:Reason>
                <s:Text xml:lang="en-US">Object reference not set to an instance of an object.</s:Text>
            </s:Reason>
            <s:Detail>
                <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <HelpLink i:nil="true"/>
                    <InnerException i:nil="true"/>
                    <Message>Object reference not set to an instance of an object.</Message>
                    <StackTrace>   at ARI.DriveAwayMgr.DriveAwaySrvc.GetRequestDetail(ARIRqst rqst) in d:\[REDACTED]\DriveAwaySrvc.svc.cs:line 189&#xD;
   at SyncInvokeGetRequestDetail(Object , Object[] , Object[] )&#xD;
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
                    <Type>System.NullReferenceException</Type>
                </ExceptionDetail>
            </s:Detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:0)

<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>

来自php.net。

只需将wsdl插入到SoapClient调用中......它应该返回所有方法和参数......

您也可以将它包装在try catch块中