【问题标题】:Send New-WebServiceProxy SOAP request to multiple endpoints向多个端点发送 New-WebServiceProxy SOAP 请求
【发布时间】:2018-07-06 12:32:25
【问题描述】:

第一次使用 PS,第一次写脚本!

我有一个 wsdl 本地存储在我的主机上,它指向一个 localhost 端点。这是必要的,因为远程服务器不为 wsdl 提供服务。但是,它们是这些 SOAP 请求的有效端点。

我的网络中有多个端点,我想在引用静态 wsdl 的同时向每个端点发送 New-WebServiceProxy 请求。有没有办法使用本地 wsdl,但指定一个目标端点覆盖?

这是我目前拥有的(请原谅 cmets,我正在努力学习):

# The uri refers to the wsdl page            

$uri = ( Join-Path $PSScriptRoot "\wsdl\PublicService.wsdl" )

# Create the Web Service Proxy           
$service = New-WebServiceProxy -Uri $uri  -Namespace WebServiceProxy  -UseDefaultCredential -Verbose       

# Specify the list of target servers IP addressesr hostnames

$serverlistpath = ( Join-Path $PSScriptRoot "\servers\servers.txt" )
$servers = gc $serverlistpath


# Create an output path to the templates folderr use witin the SOAP request
$templatetemp = ( Join-Path $PSScriptRoot "\template_temp\" )


# Gets the UNC path of the script running location

$currentDirectory = Get-Location
$currentDrive = Split-Path -qualifier $currentDirectory.Path
$logicalDisk = Gwmi Win32_LogicalDisk -filter "DriveType = 4 AND DeviceID = '$currentDrive'"
$uncPath = $currentDirectory.Path.Replace($currentDrive, $logicalDisk.ProviderName)

# Execute SOAP request

$service.Backup("false", "true", "false", "false", "$uncpath\template_temp")

我计划在 servers.txt 中将其作为 ForEach 循环运行,但每次都需要能够在指向静态 wsdl 的同时设置不同的 URL。每个服务器本身并不为 wsdl 提供服务。

任何建议表示赞赏。

【问题讨论】:

    标签: powershell soap new-webserviceproxy


    【解决方案1】:

    您可能希望创建一个包含两个标题的 CSV 文件,一个用于您的服务器名称,另一个用于 URL。

    例如

    server,url SERVER01,http://www.example.com/oneendpoint SERVER02,http://www.example.com/twoendpoint

    然后您可以使用 foreach 循环遍历每个条目。您可以使用 Import-CSV cmdlet 在 PowerShell 中轻松导入 csv 文件

    【讨论】:

    • 感谢您的回复,不胜感激。但是,我仍然感到困惑,因为即使我使用带有两个标头的 CSV,New-WebServiceProxy 仍然会引用本地 wsdl 中规定的端点。我正在寻找一种方法来覆盖在 WSDL 中编码的端点,因为我的服务器都不会实时为 wsdl 提供服务。
    猜你喜欢
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 2018-08-07
    相关资源
    最近更新 更多