2016-05-23 65 views
1

我需要将SOAP请求发送到某个服务器。 我知道正是SOAP请求权举例如下:PHP中的非wsdl SOAP请求

<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> 

而且我已经运行的C#示例:

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); 

    } 
} 

我试图做同样的代码在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); 

但请求和回调从这个代码是下一个:

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

请求:

<?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> 

回调:

<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> 

看来的请求主体是空的。

这是什么意思?如果在wsdl-mode和request body中的调用是空的,那么wsdl-schema会被破坏,对吧? 如果wsdl被破坏手动构建最初的正确SOAP请求的方式是什么?任何人都可以举个例子吗? 此外,在初始权利SOAP请求中给出的数据足以手动构建此请求?或者,我需要一些额外的(命名空间等)

回答

0

试试下面的代码:

$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')); 

此代码应该给你以下要求:

<?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> 
+0

谢谢,这个代码给出确切上述要求。但是回应仍旧存在,其中: '代码'对象引用未设置为对象的实例.'代码' 这意味着请求必须与我的问题开始时的正确示例完全相同。 我应该改变什么来构造完全相同? –