0
目前我正在使用WSHttpBinding的WCF服务。到目前为止,该服务在.NET应用程序中运行良好但是,当涉及到在PHP中使用此服务时,它会引发错误。该错误是由于PHP将null作为参数发送给WCF服务而导致的。使用WSHttpBinding调用WCF服务
服务合同看起来如下:
[ServiceContract]
public interface IWebsite : IWcfSvc
{
[OperationContract]
[FaultContract(typeof(ServiceException))]
ResponseResult LostPassword(RequestLostPassword request);
}
所使用的参数的数据合约的样子:
[DataContract]
public class RequestLostPassword
{
[DataMember(IsRequired = true)]
public string Email { get; set; }
[DataMember(IsRequired = true)]
public string NewPassword { get; set; }
[DataMember(IsRequired = true)]
public string CardNumber { get; set; }
[DataMember(IsRequired = true)]
public DateTime RequestStart { get; set; }
}
因为我不是专家,我花了一段时间来得到的PHP代码工作,但我最终写了这样的脚本:
$parameters = array(
'Email' => "[email protected]",
'NewPassword' => "test",
'CardNumber' => "1234567890",
'RequestStart' => date('c')
);
$svc = 'Website';
$port = '10007';
$func = 'LostPassword';
$url = 'http://xxx.xxx.xxx.xxx:'.$port.'/'.$svc;
$client = @new SoapClient(
$url."?wsdl",
array(
'soap_version' => SOAP_1_2,
'encoding'=>'ISO-8859-1',
'exceptions' => true,
'trace' => true,
'connection_timeout' => 120
)
);
$actionHeader[] = new SoapHeader(
'http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/I'.$svc.'/'.$func,
true
);
$actionHeader[] = new SoapHeader(
'http://www.w3.org/2005/08/addressing',
'To',
$url,
true
);
$client->__setSoapHeaders($actionHeader);
$result = $client->__soapCall($func, array('parameters' => $parameters));
我什么也没有删除这就是为什么它没有将参数传递给WCF服务。我有另一种服务,虽然不需要参数,但工作得很好。有人能解释为什么发生这种情况吗我是一个完整的PHP noob,只是希望得到这个作为开发该网站的人的例子。