如何通过SOAP [PHP]使用WS-Security来使用安全的Web服务?

时间:2013-09-13 01:35:31

标签: php web-services soap wsdl ws-security

我正在尝试连接到安全的网络服务(HTTPS - TLS v3)但我收到此错误:

  

未捕获的SoapFault异常:[WSDL] SOAP-ERROR:解析WSDL:   无法加载   'https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0'   :无法加载外部实体   “https://integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0

这是我用过的代码:

$momurl = "integrationdev.momentum.co.za/sales/CRMService/CRMLeadService_v1_0";

//Perform Request
$client = new SoapClient(
  "https://" . urlencode($username) . ":" . urlencode($password) . "@$momurl",
      array(
          'login' => $username,
          'password' => $password
      )
 );

$params = new stdClass(); 
$params->LeadSourceId = $lsid;
$params->AffiliateLeadReference = $alref;
$params->Title = $title;
$params->Initials = $initials;
$params->PreferredName = $pname;
$params->FirstName = $username;
$params->LastName = $userlname;
$params->PreferredCorrespondenceLanguage = $lang;
$params->PreferredCommunicationMethod = $comm;
$params->Campaign = $camp;
$params->HomePhoneNumber = $phonesubmit;
$params->BusinessPhoneNumber = $phonesubmit;
$params->MobilePhoneNumber = $phonesubmit;
$params->EmailAddress = $useremail;
$params->Notes = $u_script;
$params->ProductCategories = $prodcat;

try { 
    $result = $client->createLead($params); 
} catch (Exception $e) { 
    $msgs = $e->getMessage();
    if($debug) echo "Error: $msgs"; 
} 

代码似乎不起作用。我在认证部分不太确定。这是WSDL的样子:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="CRMLeadService" 
        targetNamespace="http://www.momentum.co.za/crm/service/application/CRMLeadService/v1.0" 
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:tns="http://www.momentum.co.za/crm/service/application/CRMLeadService/v1.0" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <wsdl:types>
        <xsd:schema targetNamespace="http://www.momentum.co.za/crm/service/application/CRMLeadService/v1.0" 
                    xmlns:lead="http://www.momentum.co.za/crm/service/type/application/Lead/v1.0" 
                    xmlns:systemFault="http://www.momentum.co.za/crm/service/type/fault/SystemFault/v1.0">

            <xsd:import namespace="http://www.momentum.co.za/crm/service/type/application/Lead/v1.0" schemaLocation="../xsd-src/Lead_1_0.xsd"/>
            <xsd:import namespace="http://www.momentum.co.za/crm/service/type/fault/SystemFault/v1.0" schemaLocation="../xsd-src/SystemFault_1_0.xsd"/>

            <xsd:element name="SystemFault_fault">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="system_fault" type="systemFault:SystemFaultMessageType"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

            <xsd:element name="CreateLeadRequest">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="createLead" type="lead:LeadType"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

            <xsd:element name="CreateLeadResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="leadReferenceNumber" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>  
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="SystemFault_faultMsg">
        <wsdl:part element="tns:SystemFault_fault" name="parameters"/>
    </wsdl:message>

    <wsdl:message name="CreateLeadRequest">
        <wsdl:part element="tns:CreateLeadRequest" name="parameters"/>
    </wsdl:message>

    <wsdl:message name="CreateLeadResponse">
        <wsdl:part element="tns:CreateLeadResponse" name="parameters"/>
    </wsdl:message>

    <wsdl:portType name="CRMLeadService_v1_0">

        <wsdl:operation name="createLead">
            <wsdl:documentation>Creates lead on CRM</wsdl:documentation>
            <wsdl:input message="tns:CreateLeadRequest" name="CreateLeadRequest"/>
            <wsdl:output message="tns:CreateLeadResponse" name="CreateLeadResponse"/>
            <wsdl:fault message="tns:SystemFault_faultMsg" name="systemFault"/>
        </wsdl:operation>

    </wsdl:portType>

    <wsdl:binding name="CRMLeadServiceSOAP_v1_0" type="tns:CRMLeadService_v1_0">

        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

        <wsdl:operation name="createLead">
            <soap:operation soapAction="http://www.momentum.co.za/crm/service/application/CRMLeadService/createLead"/>
            <wsdl:input name="CreateLeadRequest">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="CreateLeadResponse">
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="systemFault">
                <soap:fault name="systemFault" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>

    </wsdl:binding>

    <wsdl:service name="CRMLeadService_v1_0">
        <wsdl:documentation>Provides operation that enables the creation of leads on CRM</wsdl:documentation>
        <wsdl:port binding="tns:CRMLeadServiceSOAP_v1_0" name="CRMLeadServiceSOAP_v1_0">
            <soap:address location="http://localhost:9080/WebToLeadServiceSOAP/services/CRMLeadService_v1_0"/>
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

我这样做了吗?任何帮助将非常感谢。谢谢!

0 个答案:

没有答案