【问题标题】:SOAP call in PHP not working at allPHP中的SOAP调用根本不起作用
【发布时间】:2017-09-08 05:17:59
【问题描述】:

很遗憾,我以前从未使用过 SOAP,所以我希望无论如何我都能很好地表达自己。

我有以下 SOAP 请求(用于在 HPSM 中创建票证):

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:SubmitIntApiIncidentRequest attachmentInfo="?" attachmentData="?" ignoreEmptyElements="true" updateconstraint="-1">
         <ns:model query="?">
            <ns:keys query="?" updatecounter="?">
               <!--Optional:-->
               <ns:id type="Decimal" mandatory="?" readonly="?">?</ns:id>
            </ns:keys>
            <ns:instance query="?" uniquequery="?" recordid="?" updatecounter="?">
               <!--Optional:-->
               <ns:registrationId type="String" mandatory="?" readonly="0">HPSM Registration ID</ns:registrationId>
               <!--Optional:-->
               <ns:contactId type="String" mandatory="?" readonly="?">???</ns:contactId>
               <!--Optional:-->
               <ns:affectedUserId type="String" mandatory="?" readonly="?">User ID</ns:affectedUserId>
               <!--Optional:-->
               <ns:serviceId type="String" mandatory="?" readonly="?">?</ns:serviceId>
               <!--Optional:-->
               <ns:affectedCiId type="String" mandatory="?" readonly="?">?</ns:affectedCiId>
               <!--Optional:-->
               <ns:priority type="String" mandatory="?" readonly="?">?</ns:priority>
               <!--Optional:-->
               <ns:title type="String" mandatory="?" readonly="?">?</ns:title>
               <!--Optional:-->
               <ns:description type="String" mandatory="?" readonly="?">description</ns:description>
               <!--Optional:-->
               <ns:returnCode type="String" mandatory="?" readonly="?">?</ns:returnCode>
               <!--Optional:-->
               <ns:returnMessage type="String" mandatory="?" readonly="?">?</ns:returnMessage>
               <!--Optional:-->
               <ns:returnTicketId type="String" mandatory="?" readonly="?">?</ns:returnTicketId>
               <!--Optional:-->
               <ns:submittedBy type="String" mandatory="?" readonly="?">?</ns:submittedBy>
               <!--Optional:-->
               <ns:submitterGroup type="String" mandatory="?" readonly="?">?</ns:submitterGroup>
               <!--Optional:-->
               <ns:assignmentGroup type="String" mandatory="?" readonly="?">?</ns:assignmentGroup>
               <!--Optional:-->
               <ns:externalReferenceId type="String" mandatory="?" readonly="?">?</ns:externalReferenceId>
               <!--Optional:-->
               <ns:category type="String" mandatory="?" readonly="?">?</ns:category>
               <!--Optional:-->
               <ns:resolveImmediately type="Boolean" mandatory="?" readonly="?">?</ns:resolveImmediately>
               <!--Optional:-->
               <ns:solutionCode type="String" mandatory="?" readonly="?">?</ns:solutionCode>
               <!--Optional:-->
               <ns:solution type="String" mandatory="?" readonly="?">?</ns:solution>
               <!--Optional:-->
               <ns:contactInfo type="String" mandatory="?" readonly="?">?</ns:contactInfo>
               <!--Optional:-->
               <ns:incidentType type="String" mandatory="?" readonly="?">?</ns:incidentType>
               <!--Optional:-->
               <ns:attachments>
                  <!--Zero or more repetitions:-->
                  <com:attachment xm:contentType="application/?" href="?" contentId="?" action="?" name="?" type="?" len="?" charset="?" upload.by="?" upload.date="?" attachmentType="?">cid:933455187673</com:attachment>
               </ns:attachments>
            </ns:instance>
            <!--Optional:-->
            <ns:messages>
               <!--Zero or more repetitions:-->
               <com:message type="String" mandatory="?" readonly="?" severity="?" module="?">?</com:message>
            </ns:messages>
         </ns:model>
      </ns:SubmitIntApiIncidentRequest>
   </soapenv:Body>
</soapenv:Envelope>

现在我的 soapcall.php 文件中有以下代码:

    <?php         

    $wsdl ='asdf?wsdl';
    $client = new SoapClient($wsdl, array('login' => "user", 'password' => "pw"));


    $request = array(
        'SubmitIntApiIncident'=>(array(
            'model' => '',
            'registrationID' => 'registrationid',
            'contactId' => 'me',
            'affectedUserId' => 'affuser',
            'serviceId' => 'serviceid',
            'affectedCiId' => '',
            'priority' => '4',
            'title' => 'Test Title',
            'description' => 'description',
            'submittedBy' => 'me',
            'assignmentGroup' => 'assignment group',
            'externalReferenceId' => '',
            'category' => 'incident',
            'resolveImmediately' => ''
        )));

    $response = $client->__soapCall("SubmitIntApiIncident", $request);
    var_dump($response);


?>

这根本不起作用 - 现在我没有收到任何错误消息,只有一个空白页。但是每次我更改代码中的某些内容时,都会出现另一条错误消息。所以我什至不知道我是否走在正确的轨道上,或者我所做的一切只会让事情变得更糟。

如果您能告诉我我的代码中是否有任何大错误,或者我如何成功地使用 php 文件提交票证,我将不胜感激。

【问题讨论】:

  • 也许你可以在这里找到一些信息:stackoverflow.com/questions/3572414/…
  • 谢谢,但很遗憾我还没有找到任何解决方案。
  • 在 PHP 代码的头部添加 error_reporting(E_ALL|E_NOTICE); 以查看所有错误和警告。
  • 谢谢你,很遗憾页面还是空的。
  • 我想我只是想通了一点:我总是尝试使用“__soapCall”函数,但我认为“__doRequest”函数是我需要的,因为我正在尝试发送数据从 php 文件到 SOAP API,反之亦然。但是无论我尝试使用 doRequest 函数提交什么,都没有任何效果。

标签: php web-services soap


【解决方案1】:

使用 __soapCall 方法是一种好方法。也可以直接使用操作名作为方法如$client-&gt;SubmitIntApiIncident()

您应该明确地使用 WSDL 到 php 生成器,以避免浪费您的时间搜索问题。

使用 WSDL 到 php 生成器的好处很多:

  • 构建请求时不要想知道如何构建它,只需使用一个好的 IDE 让自动完成功能显示您要传递的数据
  • 使用生成的类的方法发送请求,该类可以干净地处理错误和响应
  • 使用干净的对象获取响应
  • 从生成的类中获取帮助以定位错误
  • 不要怀疑请求的格式是否正确
  • ...

试试PackageGenerator 项目

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 2018-06-16
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多