如何通过powershell访问wsdl的命令?

问题描述 投票:0回答:1

我注意到使用这个脚本:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$id = "idofadmin"
$pw = 'Admin123password'
$wsdl = "https://siteofwsdl.dom.com/services/MainService?wsdl"
$p = New-WebServiceProxy –Uri $wsdl
$p|Get-Member
$p.GetEntityFields(96)

返回wsdl的所有属性。但是,使用$ p.getEntityFields命令(以及所有其他命令)将继续返回错误“无法找到重载参数”类型的错误。该网站有关于getEntityFields命令的说法。

<xs:element name="getEntityFields">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="sessionId" type="xs:string" minOccurs="0" nillable="true"/>
   <xs:element name="entityTypeId" type="xs:long" minOccurs="0"/>
   <xs:element name="mode" type="xs:long" minOccurs="0"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

该网站还提供了一个肥皂请求示例,该请求通常会提取实体数据 -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services">
 <soapenv:Header/>
  <soapenv:Body>
   <ser:getEntityFields>
    <ser:sessionId>F0C6EDD44B270B1F3DD0F1492A2A1585</ser:sessionId>
    <ser:entityTypeId>96</ser:entityTypeId>        
    <ser:mode>1</ser:mode>
   </ser:getEntityFields>
  </soapenv:Body>
</soapenv:Envelope>

在PowerShell中,我需要对getEntityField命令发出代理请求?我猜是像p.getEntityFields这样的东西,其参数是sessionID,96因为它是我想要的特定的,而模式类型0因为我只想“读”它。如果那是对的 - 我如何获得会话ID?顺便说一下,网站使用的soap版本的输出是响应(部分)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Body>

      <ns:getEntityFieldsResponse xmlns:ns="http://services" xmlns:ax21="http://objects.services/xsd">

         <ns:return xsi:type="ax21:ObjectMethod" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

            <ax21:defaultValue xsi:nil="true"/>

            <ax21:fieldLength>0</ax21:fieldLength>

            <ax21:fieldSubTypeId>0</ax21:fieldSubTypeId>

            <ax21:fieldTypeId>1</ax21:fieldTypeId>

            <ax21:isRequired>false</ax21:isRequired>

            <ax21:label>Alternate Resource</ax21:label>

            <ax21:method>alternateResourceId</ax21:method>

            <ax21:methodId>1131</ax21:methodId>

            <ax21:onInsert>true</ax21:onInsert>

            <ax21:onSelect>true</ax21:onSelect>

            <ax21:onUpdate>true</ax21:onUpdate>

            <ax21:sequence>0</ax21:sequence>

         </ns:return>

         <ns:return xsi:type="ax21:ObjectMethod" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

            <ax21:defaultValue xsi:nil="true"/>

            <ax21:fieldLength>0</ax21:fieldLength>

            <ax21:fieldSubTypeId>0</ax21:fieldSubTypeId>

            <ax21:fieldTypeId>1</ax21:fieldTypeId>

            <ax21:isRequired>false</ax21:isRequired>

            <ax21:label>Alternate Resource</ax21:label>

            <ax21:method>alternateResourceByTitle</ax21:method>

            <ax21:methodId>1160</ax21:methodId>

            <ax21:onInsert>true</ax21:onInsert>

            <ax21:onSelect>false</ax21:onSelect>

            <ax21:onUpdate>true</ax21:onUpdate>

            <ax21:sequence>9999</ax21:sequence>

         </ns:return>

         <ns:return xsi:type="ax21:ObjectMethod" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

            <ax21:defaultValue xsi:nil="true"/>

            <ax21:fieldLength>64</ax21:fieldLength>

            <ax21:fieldSubTypeId>0</ax21:fieldSubTypeId>

            <ax21:fieldTypeId>1</ax21:fieldTypeId>

            <ax21:isRequired>false</ax21:isRequired>

            <ax21:label>Base Calendar</ax21:label>

            <ax21:method>initialBaseCalendarTitle</ax21:method>

            <ax21:methodId>101101</ax21:methodId>

            <ax21:onInsert>true</ax21:onInsert>

            <ax21:onSelect>false</ax21:onSelect>

            <ax21:onUpdate>true</ax21:onUpdate>

            <ax21:sequence>0</ax21:sequence>

         </ns:return>

         <ns:return xsi:type="ax21:ObjectMethod" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

            <ax21:defaultValue xsi:nil="true"/>

            <ax21:fieldLength>6</ax21:fieldLength>

            <ax21:fieldSubTypeId>0</ax21:fieldSubTypeId>

            <ax21:fieldTypeId>6</ax21:fieldTypeId>

            <ax21:isRequired>false</ax21:isRequired>

            <ax21:label>Billable Rate</ax21:label>

            <ax21:method>targetBillingRate</ax21:method>

            <ax21:methodId>1116</ax21:methodId>

            <ax21:onInsert>true</ax21:onInsert>

            <ax21:onSelect>true</ax21:onSelect>

            <ax21:onUpdate>true</ax21:onUpdate>

            <ax21:sequence>0</ax21:sequence>

         </ns:return>
powershell web-services
1个回答
0
投票

通过一些试验和错误,我能够回答这个问题 - 如果这里有额外的代码,请告诉我,我可以删除它。但以下确实适用于我试图访问的wsdl。看起来这里不需要xmlsoap和invoke-webrequest,因为从新的WebServiceProxy开始的一切都是我们真正想要的工作。如果您输入不带任何()的命令,则实际请求命令的参数。 PowerShell为您提供了预期数据类型列表 - 强制我在需要时使用类型[ref]。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$id = "idoflogin"
$pw = 'adminpw'
$wsdl = "https://site.dom.com/services/MainService?wsdl"
$p = New-WebServiceProxy -Uri $wsdl -Credential $creds -Namespace Proxy 
$sessionD = $p.login($id, $pw, $false, $false)
$p.getEntityFields($sessionD, '96', '0', '1', '0')
$p.logout($sessionD, [ref]$false, [ref]$false)
© www.soinside.com 2019 - 2024. All rights reserved.