连接到Web服务 - 将C#转换为PHP代码

时间:2014-04-24 03:41:57

标签: c# php web-services wcf soap

我有一个示例代码,我从商家提供的文档中获得。我认为代码是在C#中。我需要为PHP编写代码,但我对C#一无所知,所以我对此有疑问。我已经尝试为此编写PHP代码,但它看起来并不正确。

顺便说一句,这是一种Web服务类型的设置,它使用WCF来公开各种端点。这是他们提供给我的终点:http://services.scorpion.biz/Public/Leads/ExternalLead.svc

这是C#代码:

public bool SubmitLead(string contactName, string contactNumber) {

    bool outcome = false;
    string message = string.Empty;

    if (contactNumber.Length <= 9) {
        message = "Telephone number is too short";
        outcome = false;
    } else if (contactNumber.Length > 11) {
        message = "Telephone number is too long";
        outcome = false;
    } else if (contactNumber.Length == 10 && contactNumber[0] != '0') {
        message = "Telephone must start with a ZERO";
        outcome = false;
    } else if (contactNumber.Length == 11 && contactNumber.Substring(0, 2) != "27") {
        message = "Telephone must start with a 27";
        outcome = false;
    } else {
        WSExternalLead.LeadRequestMessage request = new
        WSExternalLead.LeadRequestMessage();
        request.Message = “Your Keyword” + ". Contact Name: " + contactName + ".
        Contact Number: " + contactNumber;
        request.TelephoneNumber = contactNumber;
        request.Network = “IMU”;
        request.ReceivedTime = DateTime.Now;

        using (WSExternalLead.ExternalLeadClient client = new WSExternalLead.ExternalLeadClient()) {

            try {
                WSExternalLead.LeadResponseMessage response = null;
                response = client.GenerateLead(request);

                if (response.Result != true) {
                    message = "We were unable to process your request at this
                    time. Error: " + response.ErrorMessage;
                    outcome = false;
                } else {
                    message = "Thank you for your interest in Scorpion Legal
                    Protection. We will get back to you shortly.";
                    outcome = true;
                }
            } catch (FaultException fx) {
                message = "We were unable to process your request at this time.
                Fault: " + fx.Message;
                outcome = false;
            } catch (Exception ex) {
                message = "We were unable to process your request at this time.
                Exception: " + ex.Message;
                outcome = false;
            }
        }
    }

    HttpContext.Current.Session["OUTCOME"] = outcome;
    HttpContext.Current.Session["MESSAGE"] = message;

    return outcome;
}

这是我编写的PHP代码:

// Read values to variables
$username = $_GET['un'];
$usersurname = $_GET['ul'];
$phonesubmit= $_GET['up'];
$useremail = $_GET['ue'];
$aff_id = $_GET['aff'];
$unique_id = $_GET['uid'];
$rdate = date('m/d/Y G:i:s');
$rdate = date("c", strtotime($rdate));

$wsdlFile = "http://services.scorpion.biz/Public/Leads/ExternalLead.svc?WSDL"; 
$client = new SoapClient($wsdlFile);
$variables->TelephoneNumber = $phonesubmit; 
$variables->Message = "IMU. Name: $username $usersurname. Contact Number: $phonesubmit";
$variables->Network = "IMU";
$variables->ReceivedTime = $rdate;
$result = $client->GenerateLead($variables); 
$returnMessage = $result->Result;
$returnMessage = trim($returnMessage);
if ($returnMessage == ""){
    $returnMessage = $result->ErrorMessage;
}

如何解决这个问题的任何想法将不胜感激。感谢。

0 个答案:

没有答案