螳螂 issue_relationship_add

Mantis issue_relationship_add

我有管理 Mantis 'tickets'、更新、添加注释、添加附件的功能,但我在添加与其他票证的关系时遇到了问题。 我可以阅读票证并获得关系:$mantis = New-WebServiceProxy -Uri http://tickets.empyreanbenefits.com/api/soap/mantisconnect.php?wsdl $ticketdetails = $mantis.mc_issue_get($用户名,$密码,$ticket) $ticketdetails.relationships

但是当我尝试添加关系时:

$mantis = New-WebServiceProxy -Uri http://tickets.empyreanbenefits.com/api/soap/mantisconnect.php?wsdl
$Relationship = New-Object "Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1pi_soap_mantisconnect_php_wsdl.issuerelationshipadd"
$Relationship.id = $Ticket 
$Relationship.Target_id = $TargetID
$Relationship.relationship.id = 3
$mantis.mc_issue_relationship_add($Username, $Password, $ticket, $Relationship)

我收到这个错误:

New-Object : Cannot find type [Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1pi_soap_mantisconnect_php_wsdl.issuerelationshipadd]: verify that the assembly containing this type is loaded.

试试这个方法:

$mantis = New-WebServiceProxy -Uri http://tickets.empyreanbenefits.com/api/soap/mantisconnect.php?wsdl
$ProxyType = $mantis.GetType().Namespace
$Relationship = New-Object("$ProxyType.issuerelationshipadd")
$Relationship.issue_id = $Ticket 
$Relationship.Target_id = $TargetID
$Relationship.relationship.id = 3
$mantis.mc_issue_relationship_add($Username,$Password,$ticket,$Relationship)

查看方法定义:

$mantis.mc_issue_relationship_add

# OUTPUT:   
#
# OverloadDefinitions
# -------------------
# string mc_issue_relationship_add(string username, string password, string issue_id, Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1pi_soap_mantisconnect_php_wsdl.RelationshipData relationship)

可以看到正确的类型是RelationshipData

$Relationship = New-Object ($mantis.GetType().Namespace + ".RelationshipData")

非常感谢 Marsze 的上述回复。

最终脚本为:

$uri = "http://tickets.empyreanbenefits.com/api/soap/mantisconnect.php?wsdl"
$mantis = New-WebServiceProxy -Uri $uri
$namespace = $mantis.GetType().Namespace
$relationship = New-Object "$namespace.RelationshipData"
$relationship.id = $Ticket 
$relationship.target_id = $targetId
$type = New-Object "$namespace.ObjectRef"
$type.id = 2
$relationship.type = $type
$mantis.mc_issue_relationship_add($username, $password, $ticket, $relationship)