是否可以通过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&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>
答案 0 :(得分: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"
取消注释。