web-services - 我可以使用 PowerShell 的 New-WebServiceProxy 过滤基于 WSDL 的 SOAP 查询以仅发送一个参数吗?

标签 web-services powershell

问题:对 ServiceNow 的 ../cmdb_ci_win_server.do?WSDL 表的所有 Web 服务调用都返回零结果。

原因:我正在使用 PowerShell 的 New-WebServiceProxy 方法,该方法根据 ServiceNow 提供的 WSDL 定义动态创建一个 .NET .dll。 WSDL 定义了 174 个参数,我希望只定义和查询其中一个参数,但是当使用 .dll 时,它总是在其查询的 WHERE 子句中发送其他 173 个空参数,这显然会导致不匹配的情况。

希望:动态 .dll 让我可以创建一个包含 174 个参数的参数对象,然后让我根据需要设置属性。我是否可以以某种方式创建一个仅包含我需要的单个参数的类似对象?我已经尝试使用 $param.PSObject.TypeNames.Insert(0,$paramClassName) 这样做,但是 $wsproxy.getRecords($param) 调用不能接受生成的 param 对象。此外,我无法直接添加 native 属性,只能添加 NoteProperties。恢复使用原始参数对象,我可以删除 173 个参数吗?底层对象似乎是不可变的,但也许有一些我从未见过的技巧?

演示代码:

$cred = Get-Credential
$wsproxy = New-WebServiceProxy -uri 'https://snowtest/cmdb_ci_win_server.do?WSDL' -Credential $cred 

if ($wsproxy) {
    # Force $cred onto the new wsproxy, or it will default to non-authenticated calls
    $wsproxy.Credentials = $cred

    # The parameter object we'll send with the query must be built from the custom object. 
    # That requires we extract the class name from the method's parameter definition.  
    # All my attempts to create a custom query object failed, including forcing the classname. 
    $overloadDefinitions = $wsproxy.getRecords.OverloadDefinitions
    $paramClassName = $overloadDefinitions[0] -ireplace '^[^(]+\(([^ ]+).+$', '$1'
    $param = New-Object $paramClassName
    $param.host_name = 'ServerName'
    $wsproxy.getRecords($param)
}

最佳答案

我不确定这是否适用于您的要求,但在我遵循这些说明之前,我无法成功与 ServiceNow Web 服务进行交互。

https://wiki.servicenow.com/index.php?title=Microsoft_.NET_Web_Services_Client_Examples

基本上,您正在生成一个 .NET Web 客户端,您需要取消选中该 URL 中要求中指定的框。

希望这可以帮助!

关于web-services - 我可以使用 PowerShell 的 New-WebServiceProxy 过滤基于 WSDL 的 SOAP 查询以仅发送一个参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14124352/

相关文章:

c# - 运行空间 PowerShell 输出

windows - 无法在Windows中停止ZooKeeper

python - 如何从 Odoo v10 中删除此 Controller 错误

c# - 从 Web 服务器加载 html 页面时,HtmlAgilityPACK 显示错误 "The given path' s 格式不受支持

web-services - 使用 JAX-WS : Use wsimport support for asynchrony or roll my own? 的异步 Web 服务调用

powershell - 从日志文件中删除前 N 行的最有效方法

powershell - 是否可以在 powershell 中自定义错误显示?

c# - 服务引用错误-使用MessageContractAttribute和其他类型的参数进行操作

c# - WCF: "Failed to open System.ServiceModel.Channels.ClientReliableDuplexSessionChannel"

powershell - Powershell FTPWebRequest和EnableSsl = True