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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题