xsi:type 属性未解析为类型定义
你们知道如何修复它吗?我尝试将 type_name 作为 Lead 传递,但它也不起作用。
xmlns:soap11env =“http://schemas.xmlsoap.org/soap/envelope/”>soap11env:Bodysoap11env:Faultsoap11env:Client.SchemaValidationError:1:0:错误:SCHEMASV:SCHEMAV_CVC_ELT_4_2: 元素“{http://soap.sforce.com/2005/09/outbound}sObject”,属性 '{http://www.w3.org/2001/XMLSchema-instance}type':QName 值 xsi:type 的“{urn:sobject.enterprise.soap.sforce.com}Lead” 属性未解析为类型 定义。%
我的代码:
import logging
from spyne.model.primitive import Unicode, String, Integer64
from spyne.model.complex import ComplexModel
from spyne.service import ServiceBase
from spyne.decorator import rpc
class SObjectType(ComplexModel):
__namespace__ = 'urn:sobject.enterprise.soap.sforce.com'
__type_name__ = 'sObject'
Id = String
Company_ID__C = Integer64
Company_Size_Text__c = Unicode
class NotificationType(ComplexModel):
Id = Unicode
sObject = SObjectType
class notificationsType(ComplexModel):
__namespace__ = 'http://soap.sforce.com/2005/09/outbound'
__type_name__ = 'notifications'
OrganizationId = Unicode
ActionId = Unicode
SessionId = String(nillable="true")
Notification = NotificationType.customize(max_occurs='100')
class SomeService(ServiceBase):
@rpc(notificationsType)
def MyMethod(ctx, notificationsType):
print(notificationsType)
if __name__ == '__main__':
from spyne.application import Application
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.info('listening to http://127.0.0.1:8080')
application = Application([SomeService],
tns='http://soap.sforce.com/2005/09/outbound',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11())
wsgi_application = WsgiApplication(application)
server = make_server('127.0.0.1', 8080, wsgi_application)
server.serve_forever()
这是请求:
curl --header“内容类型:text/xml”--data @“/home/sample_request.xml” “http://127.0.0.1:8080/?wsdl”
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://soap.sforce.com/2005/09/outbound">
<OrganizationId>082342234242</OrganizationId>
<ActionId>3432342DFSFDf343</ActionId>
<SessionId xsi:nil="true"/>
<Notification>
<Id>34FG23234343irKYQAY</Id>
<sObject xsi:type="sf:Lead" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<sf:Id>00Q4100000vNZBlEAO</sf:Id>
<sf:Company_ID__C>4203320</sf:Company_ID__C>
<sf:Company_Size_Text__c>501-1,000</sf:Company_Size_Text__c>
</sObject>
</Notification>
<Notification>
<Id>6565ffd45eewwe322323</Id>
<sObject xsi:type="sf:Lead" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<sf:Id>3453453453453</sf:Id>
<sf:Company_ID__C>4556456</sf:Company_ID__C>
<sf:Company_Size_Text__c></sf:Company_Size_Text__c>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
Do you guys have any idea how to fix it? I've tried to pass the type_name as Lead, but It didn't work either.
xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/">soap11env:Bodysoap11env:Faultsoap11env:Client.SchemaValidationError:1:0:ERROR:SCHEMASV:SCHEMAV_CVC_ELT_4_2:
Element '{http://soap.sforce.com/2005/09/outbound}sObject', attribute
'{http://www.w3.org/2001/XMLSchema-instance}type': The QName value
'{urn:sobject.enterprise.soap.sforce.com}Lead' of the xsi:type
attribute does not resolve to a type
definition.</soap11env:Fault></soap11env:Body></soap11env:Envelope>%
My Code:
import logging
from spyne.model.primitive import Unicode, String, Integer64
from spyne.model.complex import ComplexModel
from spyne.service import ServiceBase
from spyne.decorator import rpc
class SObjectType(ComplexModel):
__namespace__ = 'urn:sobject.enterprise.soap.sforce.com'
__type_name__ = 'sObject'
Id = String
Company_ID__C = Integer64
Company_Size_Text__c = Unicode
class NotificationType(ComplexModel):
Id = Unicode
sObject = SObjectType
class notificationsType(ComplexModel):
__namespace__ = 'http://soap.sforce.com/2005/09/outbound'
__type_name__ = 'notifications'
OrganizationId = Unicode
ActionId = Unicode
SessionId = String(nillable="true")
Notification = NotificationType.customize(max_occurs='100')
class SomeService(ServiceBase):
@rpc(notificationsType)
def MyMethod(ctx, notificationsType):
print(notificationsType)
if __name__ == '__main__':
from spyne.application import Application
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.info('listening to http://127.0.0.1:8080')
application = Application([SomeService],
tns='http://soap.sforce.com/2005/09/outbound',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11())
wsgi_application = WsgiApplication(application)
server = make_server('127.0.0.1', 8080, wsgi_application)
server.serve_forever()
This is the request:
curl --header "Content-Type: text/xml" --data
@"/home/sample_request.xml"
"http://127.0.0.1:8080/?wsdl"
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://soap.sforce.com/2005/09/outbound">
<OrganizationId>082342234242</OrganizationId>
<ActionId>3432342DFSFDf343</ActionId>
<SessionId xsi:nil="true"/>
<Notification>
<Id>34FG23234343irKYQAY</Id>
<sObject xsi:type="sf:Lead" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<sf:Id>00Q4100000vNZBlEAO</sf:Id>
<sf:Company_ID__C>4203320</sf:Company_ID__C>
<sf:Company_Size_Text__c>501-1,000</sf:Company_Size_Text__c>
</sObject>
</Notification>
<Notification>
<Id>6565ffd45eewwe322323</Id>
<sObject xsi:type="sf:Lead" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<sf:Id>3453453453453</sf:Id>
<sf:Company_ID__C>4556456</sf:Company_ID__C>
<sf:Company_Size_Text__c></sf:Company_Size_Text__c>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此答案是我已经想在这里向您解释的内容的补充: https:https:https:// github.com/arskom/spyne/discussions/686
您的服务定义是错误的。根据您的请求文档,您需要的内容如下:
至于您遇到的错误,实际上很清楚:
您需要在“ urn:sobject.enterprise.soap.sforce.com)中拥有一个名为“ leds”的对象“名称空间。
以下片段意味着这是一个多态请求:
要解析多态性请求,您首先需要通过将
polymorphic = true
传递给入站协议实例化来启用它们。然后,您需要定义系统将接受的所有可能类型。
在这种情况下,您至少需要
Lead
对象的定义。据我所记得的,要为了注册为子类的类型,它必须在其定义上具有至少一个字段(这可能是一个错误或功能,取决于您的要求
)字段,无论如何,您需要在其定义中具有至少一个字段(在这种情况下称为Lead_field)。只要您的代码不使用它,它就无害。但是,如果您已经在铅定义中有其他字段,则不必拥有它。
This answer comes in addition to what I'm already trying to explain to you here: https://github.com/arskom/spyne/discussions/686
Your service definition is wrong. According to your request document, what you need is the following:
As for the error you are getting, it's actually pretty clear:
You need to have an object named "Lead" in the "urn:sobject.enterprise.soap.sforce.com" namespace.
The following fragment implies that this is a polymorphic request:
To parse polymorphic requests, you first need to enable them by passing
polymorphic=True
to your inbound protocol instantiation.Then, you need to define all possible types that your system will accept.
In this case, you need at least the definition for the
Lead
object.As far as I remember, for a type to register as subclass, it must have at least one field of its own in its definition (this could be a bug or a feature, depending who you ask)
So if the Lead object has no additional fields, you need to have at least one field (called lead_field in this case) in its definition anyway. It's harmless as long as your code doesn't use it. However, if you already have additional fields in the Lead definition, you don't have to have it.
工作!这是最终解决方案。
谢谢Burak!
Worked! This is the final solution.
Thanks Burak!