开发者

PHP SOAP client help!

I have to create a PHP SOAP client that sends leads, but I have never worked with SOAP before, and my XML isn't that great, here is the code I have managed to write so far. . .

<?php

    try {

        $client = new SoapClient(null, array(
        'location'  =>  "https://wwa.website.co.za/CallmasterTes/LeadService.asmx",
        'uri'       =>  "urn:Website:Callmaster:InTuch/CreateLead",
        'login'     =>  "username",
        'password'  =>  "password"
        ));

            $sysName = ' ';
            $clientCode = ' ';
            $expTimestamp = ' ';
            $schedTimestamp = ' ';

        $client->CreateLead("ExternalLead",
                        new SoapParam($sysName, "BusinessSystemName"),
                        new SoapParam($clientCode, "BusinessSystemClientCode"),
                        new SoapParam($_POST['Title'], "Title"),
                        new SoapParam($_POST['FirstName'], "FirstName"),
                        new SoapParam($_POST['Surname'], "Surname"),
                        new SoapParam($_POST['IdNumber'], "IdNumber"),
                        new SoapParam($_POST['Gender'], "Gender"),
                        new SoapParam($_POST['DateOfBirth'], "DateOfBirth"),
                        new SoapParam($_POST['Language'], "Language"),
                        new SoapParam($_POST['EmailAddress'], "EmailAddress"),
                        new SoapParam($_POST['HomeTelNumber'], "HomeTelNumber"),
                        new SoapParam($_POST['BusinessTelNumber'], "BusinessTelNumber"),
                        new SoapParam($_POST['MobileTelNumber'], "MobileTelNumber"),
                        new SoapParam($_POST['OtherTelNumber'], "OtherTelNumber"),
                        new SoapParam($_POST['PreferredTelNumberCode'], "PreferredTelNumberCode"),
                        new SoapParam($_POST['CampaignName'], "CampaignName"),
                        new SoapParam($_POST['ProductName'], "ProductName"),
                        new SoapParam($_POST['Comments'], "Comments"),
                                            new SoapParam($expTimestamp, "ExpiryTimestamp"),
                                            new SoapParam($schedTi开发者_如何学JAVAmestamp, "ScheduledTimestamp"),
                        );

    }

    catch (SoapFault $fault) {
        trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
    }

?>

The following is a sample SOAP 1.2 request and response that I was given by the developers on the server side of things.

POST /CallmasterTest/LeadService.asmx HTTP/1.1
Host: wwa.website.co.za
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <CreateLead xmlns="urn:Website:Callmaster:InTuch">
      <Lead>
        <BusinessSystemName>string</BusinessSystemName>
        <BusinessSystemClientCode>int</BusinessSystemClientCode>
        <Title>Mr or Ms or Mrs or Miss...etc</Title>
        <FirstName>string</FirstName>
        <Surname>string</Surname>
        <IdNumber>string</IdNumber>
        <Gender>Male or Female</Gender>
        <DateOfBirth>date</DateOfBirth>
        <Language>string</Language>
        <EmailAddress>string</EmailAddress>
        <HomeTelNumber>string</HomeTelNumber>
        <BusinessTelNumber>string</BusinessTelNumber>
        <MobileTelNumber>string</MobileTelNumber>
        <OtherTelNumber>string</OtherTelNumber>
        <PreferredTelNumberCode>Business or Home or Mobile or Other</PreferredTelNumberCode>
        <CampaignName>string</CampaignName>
        <ProductName>string</ProductName>
        <Comments>string</Comments>
        <ExpiryTimestamp>dateTime</ExpiryTimestamp>
        <ScheduledTimestamp>dateTime</ScheduledTimestamp>
      </Lead>
    </CreateLead>
  </soap12:Body>
</soap12:Envelope>

The response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <CreateLeadResponse xmlns="urn:Website:Callmaster:InTuch">
      <CreateLeadResult>
        <Success>boolean</Success>
        <StatusMessage>string</StatusMessage>
        <LeadGuid>guid</LeadGuid>
        <Errors>
          <LeadError ErrorLevel="Information or Warning or Error">
            <Message>string</Message>
            <Field>string</Field>
          </LeadError>
          <LeadError ErrorLevel="Information or Warning or Error">
            <Message>string</Message>
            <Field>string</Field>
          </LeadError>
        </Errors>
      </CreateLeadResult>
    </CreateLeadResponse>
  </soap12:Body>
</soap12:Envelope>

I have really tried everything, and googled into high heaven, but I just can't get it to work, I am sure that it's probably something small that I am missing, I would really appreciate the help, thanx!


I'm not sure if this is a copy/paste error or not, but all the _POSTs should be $_POSTs in your first code example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜