从PowerShell将继承的复杂类型传递给SOAP Web服务

时间:2015-10-19 08:06:47

标签: c# powershell soap

我试图调用遗留的SOAP Web服务,该服务接受复杂的继承类型作为参数之一:

<s:complexType name="CreditCard">
 <s:complexContent mixed="false">
  <s:extension base="tns:PaymentCardBase">
   <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="Cvv2" type="s:string"/>
   </s:sequence>
  </s:extension>
 </s:complexContent>
</s:complexType>

<s:complexType name="PaymentCardBase" abstract="true">
 <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="CardHolderName" type="s:string"/>
  <s:element minOccurs="0" maxOccurs="1" name="CardNumber" type="s:string"/>
  <s:element minOccurs="0" maxOccurs="1" name="ExpiryDate" type="s:string"/>
 </s:sequence>
</s:complexType>

电话是:

<s:element name="DoStuff">
 <s:complexType>
  <s:sequence>
   <s:element minOccurs="0" maxOccurs="1" name="accountNumber" type="s:string"/>
   <s:element minOccurs="0" maxOccurs="1" name="paymentCard" type="tns:PaymentCardBase"/>
  </s:sequence>
 </s:complexType>
</s:element>

调用它时,我这样做:

 $card = New-Object($type + ".CreditCard")
 $result = $cato.DoStuff("10024007", $card)

错误是:

Cannot convert argument "1", with value: "CATO.CreditCard", for "DoStuff" to type "CATO.PaymentCardBase": 
"Cannot convert the "CATO.CreditCard" value of type "CATO.CreditCard" to type "CATO.PaymentCardBase"."

+ $result = $cato.DoStuff<<<< ("10024007", $card)
+ CategoryInfo          : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

0 个答案:

没有答案