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>
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题