我注意到使用这个脚本:
[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>
该站点还提供了一个soap请求的例子,该请求通常会提取实体数据-
<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>
我能够通过一些尝试和错误来回答这个问题。如果这里有额外的代码,请告诉我,我可以删除它。但以下内容确实适用于我试图访问的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)