这可能是一个愚蠢的问题。如果是的话,请原谅我。
我的目标是使用PowerShell脚本调用以Java和Axis2开发的https Web服务。
下面是我创建的示例Web服务,我甚至无法通过PowerShell调用它。
Web服务方法实施
package com.webservice;
public class AreaOperations
{
public Area calculateArea(Dimension dimension)
{
Area area = new Area();
area.setArea(dimension.getLength() * dimension.getBreadth());
return area;
}
}
肥皂请求
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://webservice.com" xmlns:xsd="http://webservice.com/xsd">
<soap:Header/>
<soap:Body>
<web:calculateArea>
<!--Optional:-->
<web:dimension>
<!--Optional:-->
<xsd:breadth>100</xsd:breadth>
<!--Optional:-->
<xsd:length>200</xsd:length>
</web:dimension>
</web:calculateArea>
</soap:Body>
</soap:Envelope>
我按照堆栈交换链接In Powershell to consume a Soap complexType to keep a Soap service hot创建了以下电源shell脚本
PSScript
$URI="http://localhost:8080/axis2/services/AreaOperations?wsdl"
$proxy=New-WebServiceProxy -uri $URI
#get autogenerated namespace
$type = $proxy.GetType().Namespace
#create the data type
$CalculateAreaRequestDT = ($type + '.calculateArea')
$DimensionDT = ($type + '.dimension')
#create objects
$areaRequest = new-object ($CalculateAreaRequestDT)
$dimension = new-object ($DimensionDT)
# Assign values
$dimension.length="200"
$dimension.width="100"
$areaRequest.dimension=$dimension
#Tada
$proxy.authenticateUser($areaRequest)
但是当我执行 $ areaRequest = new-object($ CalculateAreaRequestDT)
行时,我收到以下错误New-Object : Cannot find type [Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy12_services_AreaOperations_wsdl.calculateArea]: make sure the assembly containing this type is loaded.
At line:1 char:26
+ $areaRequest = new-object <<<< ($CalculateAreaRequestDT)
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
您能否帮我解决这个问题。
此外,我们需要使用P12证书访问企业Web服务,如果有人通过PowerShell访问这些安全的Web服务,那将非常有用。
注意:发布后编辑以反映我们的PROD环境的变化以及根据Keith Hill的评论