duanhan4763 2016-05-23 18:27
浏览 99
已采纳

PHP中的非wsdl SOAP请求

I need to post SOAP request to some server. I know exactly that the right example of SOAP request as follows:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CreateOrderBroker xmlns="http://tempuri.org/">
<shortApp xmlns:a="http://schemas.datacontract.org/2004/07/ScroogeCbformsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:PIB>John Doe</a:PIB>
<a:agreeId>3155</a:agreeId>
<a:formId>55</a:formId>
<a:stateCode>1234567890</a:stateCode>
<a:telephone>1511528945</a:telephone>
</shortApp>
</CreateOrderBroker>
</s:Body>
</s:Envelope>

Also I have working C# example:

public partial class frmMain : Form
{
    public frmMain()
    {
        InitializeComponent();
    }

    public EndpointAddress EndPointAddr {
        get { return
            new EndpointAddress("https://194.126.180.186:77/ScroogeCbForms.svc?wsdl");
        }
    }

    private void btnSend_Click(object sender, EventArgs e)
    {
        ServicePointManager.ServerCertificateValidationCallback =
          new RemoteCertificateValidationCallback(IgnoreCertificateErrorHandler);

        ServicePointManager.Expect100Continue = false;


        ServiceICreditTest.CreateOrderResponse response = new CreateOrderResponse();


        ScroogeSiteGist client = new ScroogeSiteGist(Binding(), EndPointAddr);
        shortApplicationBroker shortAp = new shortApplicationBroker()
        {
            agreeId = 3155, 
            PIB = "John Doe",
            stateCode = "1234567890",
            formId = 55,
            telephone = "1511528945"

        };
        //response = client.CreateOrder("1012021013");
        response = client.CreateOrderBroker(shortAp);

        txtText.Text = string.Format("id = {0} ErrorId = {1}", response.OrderId, response.ReturnValue);

    }
}

I'm trying to make same code in PHP 5.3:

<?php
$client = new SoapClient("https://194.126.180.186:77/ScroogeCbForms.svc?wsdl", array('soap_version'   => SOAP_1_1, 'trace'   => 1));

$params = array(
    'agreeId' => 3155,
    'PIB' => 'John Doe',
    'stateCode' => '3289013768',
    'formId' => 55,
    'telephone' => '0661254877'
);

$client->CreateOrderBroker($params);

But request and callback from this code is next:

<?php
...
echo "REQUEST:<pre>".htmlspecialchars($client->__getLastRequest()) ."</pre>";
echo "CALLBACK:<pre>".htmlspecialchars($client->__getLastResponse())."</pre>";

REQUEST:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body><ns1:CreateOrderBroker/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

CALLBACK:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><CreateOrderBrokerResponse xmlns="http://tempuri.org/"><CreateOrderBrokerResult xmlns:a="http://schemas.datacontract.org/2004/07/ScroogeCbformsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:OrderId>0</a:OrderId>
<a:ReturnValue>Object reference not set to an instance of an object.</a:ReturnValue>
</CreateOrderBrokerResult>
</CreateOrderBrokerResponse>
</s:Body>
</s:Envelope>

It seems that body of request is empty.

What does it mean? If call made in wsdl-mode and request body is empty then wsdl-schema is broken, right? If wsdl is broken what is the way to construct initial right SOAP request manually? Can anyone give an example? Moreover, the data given in initial right SOAP request is enough to construct this request manually? Or I need some extra (namespaces, etc.)

  • 写回答

1条回答 默认 最新

  • dqdjfb2325 2016-05-23 19:42
    关注

    Try the following code:

    $client = new SoapClient("https://194.126.180.186:77/ScroogeCbForms.svc?wsdl", array('soap_version'   => SOAP_1_1, 'trace'   => 1));
    
    class shortApp {
        function __construct()
        {
            $this->agreeId = 3155;
            $this->PIB = 'John Doe';
            $this->stateCode = '3289013768';
            $this->formId = 55;
            $this->telephone = '0661254877';
        }
    }
    
    $sa = new shortApp();
    $shortApp = new SoapVar($sa, SOAP_ENC_OBJECT, 'shortApp', 'http://soapinterop.org/xsd');
    $response = $client->CreateOrderBroker(new SoapParam($shortApp, 'shortApp'));
    

    This code should give you the following request:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://soapinterop.org/xsd" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <SOAP-ENV:Body>
            <ns1:CreateOrderBroker>
                <shortApp xsi:type="ns2:shortApp">
                    <agreeId xsi:type="xsd:int">3155</agreeId>
                    <PIB xsi:type="xsd:string">John Doe</PIB>
                    <stateCode xsi:type="xsd:string">3289013768</stateCode>
                    <formId xsi:type="xsd:int">55</formId>
                    <telephone xsi:type="xsd:string">0661254877</telephone>
                </shortApp>
            </ns1:CreateOrderBroker>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)