我无法理解如何在 PHP SOAP 调用中传递用户定义的类型。有人可以给我提示(或手册链接)吗?
例子: 在我的 WSDL 文件中,我定义了类型:
<types>
<schema targetNamespace="http://example.com/CustData"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="personalInformation">
<complexType>
<all>
<element name="name" type="xsd:string"/>
<element name="title" type="xsd:string"/>
<element name="lang" type="xsd:string"/>
</all>
</complexType>
</element>
</schema>
我这样定义服务响应消息:
<message name='getCustDataResponse'>
<part name='Result' type='xsd:personalInformation'/>
<part name='Result1' type='xsd:string'/>
</message>
缺少的部分是 - 如何在 SOAP 服务器端初始化答案?
我试着写:
$arrRes['Result']['name'] = 'xxx';
$arrRes['Result']['title'] = 'yyy';
$arrRes['Result']['lang'] = 'zzz';
$arrRes['Result']['hehehehe1'] = 'test1';
$arrRes['Result']['hehehehe2'] = 'test2';
$arrRes['Result']['hehehehe3'] = 'test3';
$arrRes['Result']['hehehehe4'] = 'test4';
$arrRes['Result1'] = 'result1';
$arrRes['blablabla'] = 'hahaha';
return $arrRes;
客户端收到响应,当我对其进行 var_dump 时,它会显示 arrRes:
array(2) { ["Result"]=> array(7) { ["name"]=> string(3) "xxx" ["title"]=> string(3) "yyy" ["lang"]=> string(3) "zzz" ["hehehehe1"]=> string(5) "test1" ["hehehehe2"]=> string(5) "test2" ["hehehehe3"]=> string(5) "test3" ["hehehehe4"]=> string(5) "test4" } ["Result1"]=> string(7) "result1" }
我预计会出现错误,因为我初始化的数组与我定义的响应消息不匹配。
所以我想我在 wsdl 中定义的类型根本没有使用 - 所以它一定是 wsdl 或客户端或服务器代码中的错误。
提前感谢您的建议!!
尼古拉
最佳答案
我没有对 PHP 上的 SOAP 服务器端做太多工作,但是 here is an example of how to use class mapping使用 php 的 SoapClient。我相当确定 SoapServer 的工作方式完全相同。 (您甚至可以在服务器/客户端之间共享相同的类映射)。
所以你会有这样一个类:
class PersonalInformation
{
public $name;
public $title:
public $lang;
}
然后您的回复:
function getCustData()
{
$response = new PersonalInformation;
$response->name = "Me";
$response->title = "Hi World";
$response->lang = "En-US";
$arrResult = array();
$arrResult['Result'] = $response;
$arrResult['Result1'] = 'lol';
return $arrResult
}
然后只需使用像这样的类映射:
$server = new SoapServer('foo?wsdl', classmap=array('personalInformation' => 'PersonalInformation'));
//I'm not sure whether you have to use the classmap on BOTH server/client
$client = new SoapClient('foo?wsdl', classmap=array('personalInformation' => 'PersonalInformation'));
就不符合要求的响应数据的错误而言,我认为 php 不会真正对响应进行任何验证 - 只有请求。
关于php - 在 PHP SOAP 中传递用户定义的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2312022/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>