0

是否可以通过 PHP 将 SOAP 请求发布到服务器 url 并接收结果?

网址,用于发布参数:

http://example.com/stockChart.svc

帖子参数:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <getStockWeeklyChart xmlns="http://www.example.com/1">
            <request xmlns:d4p1="http://www.example.com/2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <d4p1:msInstrumentID>0</d4p1:msInstrumentID>
                <d4p1:symbol>FB</d4p1:symbol>
                <d4p1:indexSymbol>0S&amp;P5</d4p1:indexSymbol>
                <d4p1:dateInfo xmlns:d5p1="http://www.example.com/3">
                    <d5p1:startDate>2012-05-18T00:00:00</d5p1:startDate>
                    <d5p1:endDate>2013-09-16T00:00:00</d5p1:endDate>
                    <d5p1:frequency>Weekly</d5p1:frequency>
                    <d5p1:frequencyUnit>1</d5p1:frequencyUnit>
                    <d5p1:tickCount>0</d5p1:tickCount>
                </d4p1:dateInfo>
            </request>
        </getStockWeeklyChart>
    </s:Body>
</s:Envelope>
4

1 回答 1

1

确实是的。让我们举一个 PHP 使用 WCF 服务的例子:

using System;
using System.Globalization;
using System.Web.Services.Protocols;
using SalesforceService.SFDCPartner;
using System.Xml;

namespace SalesforceService
{
    public class SalesforceService : ISalesforceService
    {

        /// <summary>
        /// Simple test stub to see how PHP can communicate with .NET web service
        /// </summary>
        /// <param name="value">Any string, preferably simple like Hello or Bye</param>
        /// <returns>A string indicating the call received incoming value</returns>
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }


        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

    }
}

对应界面为:

using System;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace SalesforceService
{
    [ServiceContract]
    public interface ISalesforceService
    {
        [OperationContract]
        string GetData(string value);
    }

    [DataContract]
    public class CompositeType
    {
        bool _boolValue = true;
        string _stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return _boolValue; }
            set { _boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return _stringValue; }
            set { _stringValue = value; }
        }
    }
}

与此服务通信的 PHP 脚本:

<?php   

    $client = new SoapClient("http://server.com/salesforceservice/SalesforceService.svc?wsdl");
    $result = $client->GetData(
        array('value'   => 'really?')
    );
    echo $result->GetDataResult, "\r\n";

?>

确保您的 php.ini 设置正确extension=php_soap.dll且未注释。您可能还需要extension_dir = "ext"取消注释。

于 2013-09-17T05:33:26.743 回答