我正在尝试使用python SUDS调用Web服务方法。
当尝试创建特定的复杂类型时,SUDS会向其添加xsi:type="ns0:DeedDto"
。
创建除此之外的其他类型,SUDS不会附加xsi:type。
这里的问题是接收端无法识别此类型,然后我得到此(特定)错误:
WebFault: Server raised fault: 'Unable to cast object of type 'ServiceProxy.DeedDto' to type 'ServiceProxy.DeedDto[]
以下是WSDL URL
以下是实际代码:
def create_case(self, case_data):
""" CREATECASE """
case_dto = self.client.factory.create('ns0:CaseDto')
coordinates = self.client.factory.create('ns0:Coordinates')
coordinates.Latitude = case_data.get('Latitude', None)
coordinates.Longitude = case_data.get('Longitude', None)
coordinates.SystemId = case_data.get('SystemId', None)
case_dto.Coordinates = coordinates
case_dto.CreatedByID = case_data.get('CreatedByID', None)
case_dto.CreatedByName = case_data.get('CreatedByName', None)
case_dto.CreatedDate = case_data.get('CreatedDate', None)
case_dto.Description = case_data.get('Description', None)
case_dto.Identifier = case_data.get('Identifier', None)
case_dto.InboxGuid = case_data.get('InboxGuid', None)
case_dto.ModifiedByID = case_data.get('ModifiedByID', None)
case_dto.ModifiedByName = case_data.get('ModifiedByName', None)
case_dto.ModifiedDate = case_data.get('ModifiedDate', None)
case_dto.Name = case_data.get('Name', None)
case_dto.ObjectGuid = case_data.get('ObjectGuid', None)
case_dto.ObjectID = case_data.get('ObjectID', None)
case_dto.ObjectTypeGuid = case_data.get('ObjectTypeGuid', None)
case_dto.RefID = case_data.get('RefID', None)
case_dto.StatusGuid = case_data.get('StatusGuid', None)
case_dto.AnswerTypeGuid = case_data.get('AnswerTypeGuid', None)
case_dto.EventDate = case_data.get('EventDate', None)
case_dto.HtmlDescription = case_data.get('HtmlDescription', None)
case_dto.InOutDate = case_data.get('InOutDate', None)
case_dto.IncomingMediaTypeGuid = case_data.get(
'IncomingMediaTypeGuid', None)
case_dto.StartDate = case_data.get('StartDate', None)
case_dto.StopDate = case_data.get('StopDate', None)
""" COUNTERPART(S) """
counterparts = []
for counterpart in case_data['Counterparts']:
counterpart_Dto = self.client.factory.create(
'ns0:CounterpartDto')
counterpart_Dto.Address1 = counterpart.get('Address1', None)
counterpart_Dto.Address2 = counterpart.get('Address2', None)
counterpart_Dto.Address3 = counterpart.get('Address3', None)
counterpart_Dto.City = counterpart.get('City', None)
counterpart_Dto.CompanyName = counterpart.get('CompanyName', None)
counterpart_Dto.Country = counterpart.get('Country', None)
counterpart_Dto.EMail = counterpart.get('EMail', None)
counterpart_Dto.EMail2 = counterpart.get('EMail2', None)
counterpart_Dto.FirstName = counterpart.get('FirstName', None)
counterpart_Dto.HomePhone = counterpart.get('HomePhone', None)
counterpart_Dto.LastName = counterpart.get('LastName', None)
counterpart_Dto.MobilePhone = counterpart.get('MobilePhone', None)
counterpart_Dto.OrganisationNumber = counterpart.get(
'OrganisationNumber', None)
counterpart_Dto.RealEstateArea = counterpart.get(
'RealEstateArea', None)
counterpart_Dto.RealEstateBlock = counterpart.get(
'RealEstateBlock', None)
counterpart_Dto.RealEstateUnit = counterpart.get(
'RealEstateUnit', None)
counterpart_Dto.SocialSecurityNumber = counterpart.get(
'SocialSecurityNumber', None)
counterpart_Dto.WorkPhone = counterpart.get('WorkPhone', None)
counterpart_Dto.Zip = counterpart.get('Zip', None)
counterparts.append(counterpart_Dto)
case_dto.Counterparts = counterparts
""" DEED(S) """
deeds = []
for deed in case_data['Deeds']:
deed_Dto = self.client.factory.create('ns0:DeedDto')
coordinates = self.client.factory.create('ns0:Coordinates')
coordinates.Latitude = deed.get('Latitude', None)
coordinates.Longitude = deed.get('Longitude', None)
coordinates.SystemId = deed.get('SystemId', None)
deed_Dto.Coordinates = coordinates
deed_Dto.CreatedByID = deed.get('CreatedByID', None)
deed_Dto.CreatedByName = deed.get('CreatedByName', None)
deed_Dto.CreatedDate = deed.get('CreatedDate', None)
deed_Dto.Description = deed.get('Description', None)
deed_Dto.Identifier = deed.get('Identifier', None)
deed_Dto.InboxGuid = deed.get('InboxGuid', None)
deed_Dto.ModifiedByID = deed.get('ModifiedByID', None)
deed_Dto.ModifiedByName = deed.get('ModifiedByName', None)
deed_Dto.ModifiedDate = deed.get('ModifiedDate', None)
deed_Dto.Name = deed.get('Name', None)
deed_Dto.ObjectGuid = deed.get('ObjectGuid', None)
deed_Dto.ObjectID = deed.get('ObjectID', None)
deed_Dto.ObjectTypeGuid = deed.get('ObjectTypeGuid', None)
deed_Dto.RefID = deed.get('RefID', None)
deed_Dto.StatusGuid = deed.get('StatusGuid', None)
deed_Dto.CaseObjectID = deed.get('CaseObjectID', None)
deed_Dto.HtmlContent = deed.get('HtmlContent', None)
deed_Dto.TextContent = deed.get('TextContent', None)
""" FILE(S) """
files = []
for file_ in case_data['Files']:
file_Dto = self.client.factory.create('ns0:FileDto')
file_Dto.Data = file_.get('Data', None)
file_Dto.Extension = file_.get('Extension', None)
file_Dto.FileID = file_.get('FileID', None)
file_Dto.FileName = file_.get('FileName', None)
file_Dto.Size = file_.get('Size', None)
files.append(file_Dto)
deed_Dto.Files = files
deeds.append(deed_Dto)
case_dto.Deeds = deeds
self.validate_request(case_dto, 'create_case')
response = self.client.service.CreateCase(
self.api_key, case_dto)
return response
查看实际服务:
Service ( Service ) tns="http://tempuri.org/"
Prefixes (3)
ns0 = "http://schemas.datacontract.org/2004/07/Artvise.Mercury.Base.DataContracts.API"
ns1 = "http://schemas.microsoft.com/2003/10/Serialization/"
ns2 = "http://www.artvise.se/MercuryAPI/"
Ports (1):
(BasicHttpBinding_IService)
Methods (21):
CreateCase(xs:string apiKey, ns0:CaseDto caseDto, )
CreateDeed(xs:string apiKey, ns0:DeedDto deedDto, )
GetAnswerTypes(xs:string apiKey, )
GetCase(xs:string apiKey, xs:int objectID, )
GetCaseByIdentifier(xs:string apiKey, xs:string identifier, )
GetCaseByRefID(xs:string apiKey, xs:string refID, )
GetCasesByCounterpartSocialSecurityNumber(xs:string apiKey, xs:string socialSecurityNumber, xs:boolean includeDeeds, )
GetCasesByInboxGuid(xs:string apiKey, ns1:guid inboxGuid, xs:boolean includeDeeds, )
GetDeed(xs:string apiKey, xs:int objectID, )
GetDeedByRefID(xs:string apiKey, xs:string refID, )
GetDeedTypes(xs:string apiKey, )
GetFile(xs:string apiKey, xs:int fileID, )
GetFileByRefID(xs:string apiKey, xs:string refID, )
GetInboxes(xs:string apiKey, )
GetMediaTypes(xs:string apiKey, )
GetStatuses(xs:string apiKey, )
GetSystemMessages(xs:string apiKey, )
SetCaseCoordinates(xs:string apiKey, xs:int objectID, ns0:CoordinatesDto coordinates, )
SetCaseReference(xs:string apiKey, xs:int objectID, xs:string refID, )
SetCaseStatus(xs:string apiKey, xs:int objectID, ns1:guid statusGuid, )
Test()
Types (27):
ns0:AnswerTypeDto
ns0:ArrayOfAnswerTypeDto
ns0:ArrayOfCaseDto
ns0:ArrayOfCounterpartDto
ns0:ArrayOfDeedDto
ns0:ArrayOfDeedTypeDto
ns0:ArrayOfFileDto
ns0:ArrayOfInboxDto
ns0:ArrayOfMediaTypeDto
ns0:ArrayOfStatusDto
ns0:ArrayOfSystemMessageDto
ns0:CaseDto
ns0:CoordinatesDto
ns0:CounterpartDto
ns0:CreateObjectResult
ns0:DeedDto
ns0:DeedTypeDto
ns0:FileDto
ns0:InboxDto
ns0:MediaTypeDto
ns0:ObjectDto
ns0:OperationResult
ns0:StatusDto
ns0:SystemMessageDto
ns1:char
ns1:duration
ns1:guid
看到这是我刚刚添加的已经构建的解决方案,我需要坚持使用SUDS。 否则我可能会看别的东西。
答案 0 :(得分:0)
我使用这个(稍微愚蠢的)解决方案修复了它:
self.client = Client(self.wsdl, plugins=[XSIValidator()])
class XSIValidator(MessagePlugin):
""" Handles WSDL object differences """
def sending(self, context):
context.envelope = context.envelope.replace(
' xsi:type="ns0:DeedDto"', '')