doulu5109 2016-12-28 11:13
浏览 75

Soap PHP WSDL XML格式化

So I am using Soap client in PHP and I'm trying to make a request on some WSDL. I try to have a specific output but it seems a bit far from what I try to do. Maybe I don't do this right. I'm a bit new to WSDL.

Here is the result I want:

<SOAP-ENV:Body>
    <loc:sendSms>
           <loc:addresses>9000000000</loc:addresses>
           <loc:senderName>9000000</loc:senderName>
           <loc:message>test SMS</loc:message>
    </loc:sendSms>
</SOAP-ENV:Body>

This is what I try to fit my requirement, but it ends with a server error:

            $MCIResp = (array) $_soapClient->__soapCall('sendSms', 
                'sendMessage' => array(
                    'addresses' => '9000000000',
                    'senderName' => '9000000',
                    'message'   => 'test SMS '

            )
        ); 

And this is the error I get from this request:

"SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'sendmessage' property";

EDIT: Made some improvements on that by getting inspiration on some posts

Here is my code now:

$_soapClient = new SoapClient(
        null,
        array(
            'location' => 'http://someIP/parlayxsmsgw/services/SendSmsService?wsdl',
            'uri' => 'http://someIP/parlayxsmsgw/services/SendSmsService?wsdl',
            'trace' => 1,
            'cache_wsdl' => WSDL_CACHE_NONE,
            'use' => SOAP_LITERAL,
            'style' => SOAP_DOCUMENT,
             'stream_context' => stream_context_create(array(
                'http' => array(
                    'header' => 'servicekey: someservicekey'
                ),
            )),             
        )
    );
    $params = new \SoapVar("<sendSms><addresses>90000000000</addresses><senderName>90000000</senderName><message>test SMS</message></sendSms>",XSD_ANYXML);     

And then I do a

$_soapClient->whatEverNameHereWillBeIgnored($params);

This is now the XML I generate:

  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
     <SOAP-ENV:Body>
      <sendSms>
       <addresses>989127184955</addresses>
       <senderName>98307066</senderName>
       <message>test SMS</message>
      </sendSms>
     </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

But I receive this as a response:

Unexpected subelement sendSms

do the "loc:" are mandatory to solve this ? Because when I add it in the raw xml it says that

Undeclared namespace prefix "loc"

Thanks,

  • 写回答

1条回答 默认 最新

  • duangenshi9836 2017-01-14 11:14
    关注

    I strongly advise you to use a WSDL to PHP generator such as PackageGenerator, it will ease you the request construction so you won't have to wonder how to construct the request, it will be cristal clear.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。