来自WordPress插件的SOAP Web服务请求

时间:2017-01-13 作者:bar avital

我正在开发wordpress插件,需要执行soap调用。在理解了cURL不是选项(在我的浏览器中运行一些代码,但无法在插件中运行)之后,我尝试使用php5的SoapClient。

由于我能够打印出\\uu getFunctions()变量,因此连接似乎正常工作:

StatusResponse Status(Status $parameters)" 
[1]=> string(65) "AdministrationResponse Administration(Administration $parameters)" 
[2]=> string(74) "FetchPropertyListResponse FetchPropertyList(FetchPropertyList $parameters)" 
[3]=> string(77) "FetchPropertyGroupResponse FetchPropertyGroup(FetchPropertyGroup $parameters)" 
[4]=> string(74) "FetchPropertyInfoResponse FetchPropertyInfo(FetchPropertyInfo $parameters)" 
[5]=> string(98) "FetchPropertyAvailabilityResponse FetchPropertyAvailability(FetchPropertyAvailability $parameters)" 
[6]=> string(95) "FetchPropertyRateSummaryResponse FetchPropertyRateSummary(FetchPropertyRateSummary $parameters)" 
[7]=> string(86) "FetchStayAvailabilityResponse FetchStayAvailability(FetchStayAvailability $parameters)" 
[8]=> string(71) "PlaceReservationResponse PlaceReservation(PlaceReservation $parameters)" 
[9]=> string(89) "CheckReservationExistsResponse CheckReservationExists(CheckReservationExists $parameters)" 
[10]=> string(74) "CancelReservationResponse CancelReservation(CancelReservation $parameters)" 
[11]=> string(56) "PostPaymentResponse PostPayment(PostPayment $parameters)" 
[12]=> string(53) "PostChargeResponse PostCharge(PostCharge $parameters)" 
[13]=> string(44) "PostEFTResponse PostEFT(PostEFT $parameters)" 
[14]=> string(56) "PostMessageResponse PostMessage(PostMessage $parameters)" 
[15]=> string(50) "PlaceHoldResponse PlaceHold(PlaceHold $parameters)" 
[16]=> string(53) "CancelHoldResponse CancelHold(CancelHold $parameters)" 
[17]=> string(62) "ValidateAgentResponse ValidateAgent(ValidateAgent $parameters)" 
[18]=> string(68) "ValidateCompanyResponse ValidateCompany(ValidateCompany $parameters)" 
[19]=> string(80) "FetchPropertyReportResponse FetchPropertyReport(FetchPropertyReport $parameters)" 
[20]=> string(41) "StatusResponse Status(Status $parameters)" 
[21]=> string(65) "AdministrationResponse Administration(Administration $parameters)" 
[22]=> string(74) "FetchPropertyListResponse FetchPropertyList(FetchPropertyList $parameters)" 
[23]=> string(77) "FetchPropertyGroupResponse FetchPropertyGroup(FetchPropertyGroup $parameters)" 
[24]=> string(74) "FetchPropertyInfoResponse FetchPropertyInfo(FetchPropertyInfo $parameters)" 
[25]=> string(98) "FetchPropertyAvailabilityResponse FetchPropertyAvailability(FetchPropertyAvailability $parameters)" 
[26]=> string(95) "FetchPropertyRateSummaryResponse FetchPropertyRateSummary(FetchPropertyRateSummary $parameters)" 
[27]=> string(86) "FetchStayAvailabilityResponse FetchStayAvailability(FetchStayAvailability $parameters)" 
[28]=> string(71) "PlaceReservationResponse PlaceReservation(PlaceReservation $parameters)" 
[29]=> string(89) "CheckReservationExistsResponse CheckReservationExists(CheckReservationExists $parameters)" 
[30]=> string(74) "CancelReservationResponse CancelReservation(CancelReservation $parameters)" 
[31]=> string(56) "PostPaymentResponse PostPayment(PostPayment $parameters)" 
[32]=> string(53) "PostChargeResponse PostCharge(PostCharge $parameters)" 
[33]=> string(44) "PostEFTResponse PostEFT(PostEFT $parameters)" 
[34]=> string(56) "PostMessageResponse PostMessage(PostMessage $parameters)" 
[35]=> string(50) "PlaceHoldResponse PlaceHold(PlaceHold $parameters)" 
[36]=> string(53) "CancelHoldResponse CancelHold(CancelHold $parameters)" 
[37]=> string(62) "ValidateAgentResponse ValidateAgent(ValidateAgent $parameters)" 
[38]=> string(68) "ValidateCompanyResponse ValidateCompany(ValidateCompany $parameters)" 
[39]=> string(80) "FetchPropertyReportResponse FetchPropertyReport(FetchPropertyReport $parameters)" }
当我尝试调用其中一个函数时,我得到一个“对象引用未设置为对象的实例”错误在我发送soap请求抛出POSTMAN chrome插件之前,我就很熟悉这个错误。当身体部位缺少细节时,我发现了这个错误。

这是我设法从邮递员那里发出的请求:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <ChannelCredentials xmlns="ChartsWeb">
      <Username>???</Username>
      <Password>???</Password>
    </ChannelCredentials>
  </soap:Header>
  <soap:Body>
    <FetchPropertyInfo xmlns="ChartsWeb">
      <FetchPropertyInfoRequest>
        <PropertyInfoRequests>
          <PropertyInfoRequest PropCode="???" MySite="???"/>
        </PropertyInfoRequests>
      </FetchPropertyInfoRequest>
    </FetchPropertyInfo>
  </soap:Body>
</soap:Envelope>
并得到了预期的结果。

这是我得到的当前代码:

<?php




$client = new SoapClient("http://stage-chartsweb.chartspms.com.au/webservices/service.asmx?wsdl", array(\'trace\' => 1));

$ns = \'ChartsWeb\'; //Namespace of the WS. 

//Body of the Soap Header. 
$headerbody = array(\'Username\' => $username, 
                    \'Password\' => $password,
                    \'LoggingRequest\' => True);

//Create Soap Header.        
 $header = new SOAPHeader($ns, \'ChannelCredentials\', $headerbody);        

// //set the Headers of Soap Client. 
 $client->__setSoapHeaders($header); 

$fcs = $client->__getFunctions();

$res_FetchPropertyInfo = $client->FetchPropertyInfo(array("PropCode" => $prop_code, "MySite" => $my_site));

var_dump($client->__getLastRequest());
这是它产生的请求:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="ChartsWeb">
    <SOAP-ENV:Header>
        <ns1:ChannelCredentials>
            <ns1:Username>???</ns1:Username>
            <ns1:Password>???</ns1:Password>
            <ns1:LoggingRequest>true</ns1:LoggingRequest>
        </ns1:ChannelCredentials>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:FetchPropertyInfo/>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的身体似乎有点不正常。。

有人处理这个问题吗?

1 个回复
SO网友:bar avital

没关系,找到我的错误。。只需根据主体结构分配给函数关联数组。有时你所需要的只是把事情写下来:)

相关推荐

分发访问SOAPWeb服务的插件时的陷阱?

我想知道what pitfalls (如有?)这里的开发人员遇到了when distributing WordPress plugins 通过the WordPress plugin repository that embed a SOAP client 用于访问SOAP web services 对于关键的插件功能(或通过任何其他存储库广泛分发的任何插件)(我的假设是,一家发布插件的公司开发插件会更好。)RESTful web services 但我想通过调查其他人的意见来验证这一观点。注意,我问我们自