将Web服务客户端从c#转换为php

时间:2011-11-03 20:07:00

标签: c# php service web

我有c#示例如何使用某些Web服务。如何将这段代码看成PHP?

PartnerAPI papi = new PartnerAPI();
ApiReqHeader arh = new ApiReqHeader();

arh.clientId = "99992222";

LoginAuthenticationInfo lai = new LoginAuthenticationInfo();
lai.login = "login";
lai.pwd = "password";

ServiceAccountInfo sai = new ServiceAccountInfo();
sai.Serviceaccount = "1234567890";

GetChildAccountInfoBySearchCriteriaRequest child = new GetChildAccountInfoBySearchCriteriaRequest();

child.serviceAccountInfo = sai; // customerInfo = customer;
child.reqHeader = arh;
child.loginAuthenticationInfo = lai;


GetChildAccountInfoBySearchCriteriaResponse resp = papi.GetChildAccountInfoBySearchCriteria(child);

这只是一个文件(只有这个代码,需要获取onmp accpount信息)

我添加了classe但仍无效。这段代码有什么问题

 $papi = new SoapClient($url,
                    array(
                      "trace"      => 1,        // enable trace to view what is happening
                      "exceptions" => 0,        // disable exceptions
                      "cache_wsdl" => 0)        // disable any caching on the wsdl, encase you alter the wsdl server
 );
$arh = new ApiReqHeader();

$arh->client_id = "99992222";

$lai = new LoginAuthenticationInfo();
$lai->login = "login";
$lai->pwd = "password";

$sai = new ServiceAccountInfo();
$sai->Serviceaccount = "1234567890";

$child = new GetChildAccountInfoBySearchCriteriaRequest();

$child->serviceAccountInfo = $sai; // customerInfo = customer;
$child->reqHeader = $arh;
$child->loginAuthenticationInfo = $lai;


$resp = $papi->GetChildAccountInfoBySearchCriteria($child);
echo $resp;



class ApiReqHeader{
    public  $clientId;
}

1 个答案:

答案 0 :(得分:1)

假设您在PHP文件中使用了相同的类,并且已经包含了所需的文件,这很可能是语法:

<?php

    $papi = new PartnerAPI();
    $arh = new ApiReqHeader();

    $arh->client_id = "99992222";

    $lai = new LoginAuthenticationInfo();
    $lai->login = "login";
    $lai->pwd = "password";

    $sai = new ServiceAccountInfo();
    $sai->Serviceaccount = "1234567890";

    $child = new GetChildAccountInfoBySearchCriteriaRequest();

    $child->serviceAccountInfo = $sai; // customerInfo = customer;
    $child->reqHeader = $arh;
    $child->loginAuthenticationInfo = $lai;


    $resp = $papi->GetChildAccountInfoBySearchCriteria($child);

?>

显然,除非您在PHP应用程序中使用相同的文件,否则这不会神奇地起作用。