我正在尝试编写一个XSD来验证我的SOAP服务的响应.我觉得有必要导入http:// schemas.xmlsoap.org/soap/envelope/,而不是重新定义像Envelope,Head和Body这样的SOAP元素,但是Body的xmlsoap.org模式定义太宽泛了 - - 一旦我导入SOAP Schema,突然我的XSD(我已经为我的服务精心定制)验证了所有 SOAP消息.
我该如何处理XSD中SOAP信封,头部,主体的定义?
我怀疑问题是我正在尝试重新使用其他我不应该尝试重用的模式.当然,那些用于SOAP的Schema旨在定义(所有)SOAP消息应该是什么样子.也许我只需要在我的架构中定义我想要的特定肥皂体看起来像什么.
我可能刚刚回答了我自己的问题.也许有人有不同的解决方案?
我在编写XSD来描述来自我的一个SOAP服务的响应消息时遇到了一些麻烦.
这是我正在尝试验证的服务的示例响应:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<helloResponse xmlns="http://justinfaulkner/wsdl/1.0">
<Message>Hello, Justin!</Message>
<Message>Your lucky numbers are: 329, 9</Message>
</helloResponse>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
我的目标是使用XSD验证我的服务响应.所以,我手工编写了一个XSD,它描述了我服务的soap:Body中所有类型
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://justinfaulkner/wsdl/1.0" xmlns:tns="http://justinfaulkner/wsdl/1.0">
<xsd:complexType name="helloResponseType">
<xsd:sequence>
<xsd:element name="Message" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="helloResponse" type="tns:helloResponseType"/>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用PHP的DOMDocument :: schemaValidateSource()功能验证带有Schema(第2个代码片段)的示例响应(第一个XML片段)时,验证器指出了我的第一个明显的错误:
元素'soap:Envelope':没有匹配的全局声明可用
"糟糕,呃,"我想,"这些元素是在SOAP的命名空间中定义的,所以我需要导入SOAP的XSD."
所以我编辑了我的XSD并添加了一个导入:
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
Run Code Online (Sandbox Code Playgroud)
它奏效了!当我使用XSD验证soap响应时,DOMDocument :: schemaValidateSource返回true.
然后,作为一个完整性检查,我采取了不同的肥皂反应XSD我躺在周围:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://justinfaulkner/wsdl/1.0" xmlns:tns="http://justinfaulkner/wsdl/1.0">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
<xsd:complexType name="OtherServiceResponseType"> …
Run Code Online (Sandbox Code Playgroud) 我正在使用ember(+ data)并构建了一个简单的注册表单,但是在服务器端验证错误之后我无法使表单(和ember-data事务)正常工作.
我正在关注https://github.com/dgeb/ember_data_example作为如何使用事务的指南,它主要适用于Happy Path,但是在服务器端验证错误之后,我无法获得ember-data单击"提交"时重新提交API请求.
我做了一些挖掘,我认为我错过了一些与模型失效后重置事务有关的步骤......
您可以在http://emb.herokuapp.com/上试用该应用并重现该问题
您还可以访问https://github.com/justinfaulkner/ember-data-resubmit查看完整的源代码.
您可以使用@ example.com上的电子邮件地址在我的应用程序中填写表单,从而触发虚假的服务器端错误.Rails API将响应422并将错误对象键入用户名/电子邮件字段.
该字段应以红色突出显示错误 - 将电子邮件地址编辑为应该有效的内容,然后再次单击"提交".在chrome中打开开发人员工具时,我看不到ember-data通过点击发送http请求(但控制器中的console.log表示确实正在接收点击).
在使用错误修改字段后,ember-data(我认为)会将模型更改invalid
为uncommitted
以便在下次commit
调用时提交它.当我单击Submit时,ember-data应该将HTTP请求发送到我的api,而ember应该转换为"Congrats!".页.
然而,相反,形式就在那里.没有http请求.没有过渡到"恭喜!".
这是我更新输入后点击提交几(18)次后的屏幕截图:
以下是我的余烬应用程序的一些片段:
我的路线使用startEditing
类似于ember_data_example的做法:
App.IndexRoute = Ember.Route.extend({
model: function() {
return null;
},
setupController: function(controller) {
controller.startEditing();
},
deactivate: function() {
this.controllerFor('index').stopEditing();
}
});
Run Code Online (Sandbox Code Playgroud)
我IndexController
的模型是在ember_data_example之后建模的ContactsNewController
App.IndexController = Ember.ObjectController.extend({
startEditing: function() {
this.transaction = this.get('store').transaction();
this.set('content', this.transaction.createRecord(App.User));
},
submit: function(user){
console.log("submitting!");
this.transaction.commit(); …
Run Code Online (Sandbox Code Playgroud)