locked
Powershell WDSL Custom Types and Casting RRS feed

  • Question

  • Hi Everyone!!

    When executing the code below I seem to be getting this error and <g class="gr_ gr_27 gr-alert gr_tiny gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="27" id="27">I</g> for the life of me can't figure out why my casting is incorrect.

    Anyone have any input it will be GREATLY APPRECIATED! :)

    Happy Holidays everyone! =]

    *Sorry if I double posted, I did not mean to!*

    Cannot convert argument "Maintain_Contact_Information_for_Person_Event_Request", with value: "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType", for "Maintain_Contact_Information" to type 
    "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType": "Cannot convert the "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" value of type 
    "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" to type "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType"."
    At C:\Program Files\Sentillion\proVision\Configuration\Extra\WorkdayEmail.ps1:109 char:1
    + $webservicex.Maintain_Contact_Information($EventRequest1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    $where = 'https://wd2-impl-services1.workday.com/ccx/service/Human_Resources/v28.2?wsdl'  #Maintain_Contact_Information_for_Person_Event_Request
    
    $webservicex = New-WebServiceProxy -Uri $where -namespace "MyApi" -Credential $cred
    #$webservicex.GetType().Assembly.GetExportedTypes() | select FullName
    #$webservicex | get-member | out-string -Width 4096
    #$webservicex | gm -memberType Method
    #$webservicex | gm -memberType Property
    #$type = $webservicex.GetType().NameSpace 
    #$type | out-string -Width 4096
    #$MethodOutput = [xml]
    
    [MyApi.Maintain_Contact_Information_for_Person_Event_RequestType]$EventRequest1 = New-Object MyApi.Maintain_Contact_Information_for_Person_Event_RequestType
    $EventRequest1.Add_Only=$true
    $EventRequest1.version='v28.2'
    
    [MyApi.Business_Process_ParametersType]$BusinessProcessParameters =  New-Object MyApi.Business_Process_ParametersType
    $BusinessProcessParameters.Auto_Complete = $true
    $BusinessProcessParameters.Run_Now = $true
    [MyApi.Business_Process_Comment_DataType]$CommentData =  New-Object MyApi.Business_Process_Comment_DataType
    $CommentData.Comment = 'Test Work Email Update'
    [MyApi.Contact_Information_for_Person_Event_DataType]$MaintainContactInformationData = New-Object MyApi.Contact_Information_for_Person_Event_DataType
    $MaintainContactInformationData.Effective_Date = "2017-12-21"
    [MyApi.WorkerObjectType]$WorkerReference = New-Object MyApi.WorkerObjectType
    
    [MyApi.WorkerObjectIdType]$WorkerReferenceID = New-Object MyApi.WorkerObjectIdType
    $WorkerReferenceID.type = 'Employee_ID'
    $WorkerReferenceID.Value = '24556'
    
    [MyApi.Contact_Information_Datatype]$WorkerContactInformationData = New-Object MyApi.Contact_Information_Datatype
    [MyApi.Email_Address_Information_DataType]$EmailAddressData = New-Object MyApi.Email_Address_Information_DataType
    $EmailAddressData.Email_Address = 'Nhall@EchoMichaelCharlie.Org'
    
    [MyApi.Communication_Method_Usage_Information_Datatype]$Usage = New-Object MyApi.Communication_Method_Usage_Information_Datatype
    $Usage.Public = $true
    
    [MyApi.Communication_Usage_Type_Datatype]$TypeData = New-Object MyApi.Communication_Usage_Type_Datatype
    $TypeData.Primary = $true
    
    [MyApi.Communication_Usage_TypeObjectType]$TypeReference = New-Object MyApi.Communication_Usage_TypeObjectType
    [MyApi.Communication_Usage_TypeObjectIdType]$ObjectIdType = New-Object MyApi.Communication_Usage_TypeObjectIdType
    $ObjectIdType.type = 'Communication_Usage_Type_ID'
    $ObjectIdType.Value = 'WORK'
    
    $ObjectIdTypeArray = @($ObjectIdType) 
    #$ObjectIdTypeArray += $ObjectIdType
    
    #$TypeReference.ID = $ObjectIdType #This needs to be an Array
    $TypeReference.ID = $ObjectIdTypeArray #This needs to be an Array
    $TypeData.Type_Reference = $TypeReference
    $Usage.Type_Data = $TypeData
    #$EmailAddressData.Usage_Data = $Usage
    $EmailAddressData.Usage_Data = @($Usage)
    
    #$WorkerReference.ID = $WorkerReferenceID
    $WorkerReference.ID = @($WorkerReferenceID)
    #$WorkerContactInformationData.Email_Address_Data = $EmailAddressData
    $WorkerContactInformationData.Email_Address_Data = @($EmailAddressData)
    $MaintainContactInformationData.Worker_Reference = $WorkerReference
    $MaintainContactInformationData.Worker_Contact_Information_Data = $WorkerContactInformationData
    
    $BusinessProcessParameters.Comment_Data = $CommentData
    
    $EventRequest1.Business_Process_Parameters = $BusinessProcessParameters
    $EventRequest1.Maintain_Contact_Information_Data = $MaintainContactInformationData
    
    Write-Host 1 $EventRequest1.Add_Only
    Write-Host 2 $EventRequest1.version
    Write-Host 3 $EventRequest1.Business_Process_Parameters.Auto_Complete
    Write-Host 4 $EventRequest1.Business_Process_Parameters.Run_Now
    Write-Host 5 $EventRequest1.Business_Process_Parameters.Comment_Data.Comment
    Write-Host 6 $EventRequest1.Maintain_Contact_Information_Data.Worker_Reference.ID[0].type
    Write-Host 7 $EventRequest1.Maintain_Contact_Information_Data.Worker_Reference.ID[0].Value
    Write-Host 8 $EventRequest1.Maintain_Contact_Information_Data.Effective_Date
    Write-Host 9 $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Email_Address
    Write-Host a $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Public
    Write-Host b $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Type_Data.Primary
    Write-Host c $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Type_Data.Type_Reference.ID[0].type
    Write-Host d $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Type_Data.Type_Reference.ID[0].Value
    
    $webservicex.Maintain_Contact_Information($EventRequest1)
    
    
    [MyApi.Communication_Usage_TypeObjectIdType[]]$ObjectIdTypeArray = @(New-Object MyApi.Communication_Usage_TypeObjectIdType)
    [MyApi.Communication_Method_Usage_Information_Datatype[]]$UsageArray = @(New-Object MyApi.Communication_Method_Usage_Information_Datatype)
    [MyApi.Email_Address_Information_DataType[]]$EmailAddressDataArray = @(New-Object MyApi.Email_Address_Information_DataType)
    
    $ObjectIdTypeArray[0].type = 'Communication_Usage_Type_ID'
    $ObjectIdTypeArray[0].Value = 'WORK'
    $UsageArray[0].Public = $true
    $UsageArray[0].Type_Data = $TypeData
    $EmailAddressDataArray[0].Email_Address = 'Nhall@EchoMichaelCharlie.Org'
    
    $ObjectIdTypeArray = @($ObjectIdType)
    $WorkerReference.ID = @($WorkerReferenceID)
    $EmailAddressData.Usage_Data = @($Usage)
    
    $webservicex.Maintain_Contact_Information($EventRequest1)
    
    
    [MyApi.Communication_Usage_TypeObjectIdType[]]$ObjectIdTypeArray2 = New-Object MyApi.Communication_Usage_TypeObjectIdType
    [MyApi.Communication_Method_Usage_Information_Datatype[]]$UsageArray2 = New-Object MyApi.Communication_Method_Usage_Information_Datatype
    [MyApi.Email_Address_Information_DataType[]]$EmailAddressDataArray2 = New-Object MyApi.Email_Address_Information_DataType
    
    $ObjectIdTypeArray2[0].type = 'Communication_Usage_Type_ID'
    $ObjectIdTypeArray2[0].Value = 'WORK'
    $UsageArray2[0].Public = $true
    $UsageArray2[0].Type_Data = $TypeData
    $EmailAddressDataArray2[0].Email_Address = 'Nhall@EchoMichaelCharlie.Org'
    
    $ObjectIdTypeArray = @($ObjectIdType)
    $WorkerReference.ID = @($WorkerReferenceID)
    $EmailAddressData.Usage_Data = @($Usage)
    
    $EventRequest1.Business_Process_Parameters.Business_Process_Attachment_Data = New-Object MyApi.Business_Process_Attachment_DataType
    $EventRequest1.Business_Process_Parameters.Comment_Data.Worker_Reference = New-Object MyApi.WorkerObjectType
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Address_Data = New-Object MyApi.Address_Information_DataType
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Phone_Data = New-Object MyApi.Phone_Information_DataType
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Instant_Messenger_Data = New-Object MyApi.Instant_Messenger_Information_DataType
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Web_Address_Data = New-Object MyApi.Web_address_Information_Datatype
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Email_Comment = 'EmailComment'
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Comments = "UsageComment"
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Use_For_Reference = New-Object MyApi.Communication_Usage_BehaviorObjectType
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Use_For_Tenanted_Reference = New-Object MyApi.Communication_Usage_Behavior_TenantedObjectType
    
    $webservicex.Maintain_Contact_Information($EventRequest1)
    
    $error[0]|format-list -force
    
    $EventRequest1 | get-member
    $EventRequest1 | Select-Object -Property *
    $EventRequest1.Business_Process_Parameters | Select-Object -Property *
    $EventRequest1.Maintain_Contact_Information_Data | Select-Object -Property *
    $EventRequest1.Business_Process_Parameters.Comment_Data | Select-Object -Property *
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data | Select-Object -Property *
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0] | Select-Object -Property *
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0] | Select-Object -Property *
    $EventRequest1.Maintain_Contact_Information_Data.Worker_Contact_Information_Data.Email_Address_Data[0].Usage_Data[0].Type_Data | Select-Object -Property *


    Friday, December 22, 2017 1:05 AM

All replies

  • You post is unreadable due to HTML in the post.  Please fix.

    Use code posting tool to post code.

    The error says line 109 but there is no line 109.

    Do not try to use casts with WSDL.


    \_(ツ)_/


    • Edited by jrv Friday, December 22, 2017 1:25 AM
    Friday, December 22, 2017 1:24 AM
  • Here s a redone example of your code so you can understand what I am trying to get.

    $where = 'https://wd2-impl-services1.workday.com/ccx/service/eisenhower3/Human_Resources/v28.2?wsdl' 
    $webservicex = New-WebServiceProxy -Uri $where -namespace MyApi -Credential $cred
    
    $EventRequest1 = New-Object MyApi.Maintain_Contact_Information_for_Person_Event_RequestType
    $EventRequest1.Add_Only = 'true'
    $EventRequest1.version = 'v28.2'
    
    $BusinessProcessParameters = New-Object MyApi.Business_Process_ParametersType
    $BusinessProcessParameters.Auto_Complete = 'true'
    $BusinessProcessParameters.Run_Now = 'true'
    
    $CommentData = New-Object MyApi.Business_Process_Comment_DataType
    $CommentData.Comment = 'MyComment'
    $BusinessProcessParameters.Comment_Data = $CommentData
    
    $WOT = New-Object MyApi.WorkerObjectType
    $WOIDT = New-Object MyApi.WorkerObjectIdType
    $WOIDT.type = 'Employee_ID'
    $WOIDT.Value = '24556'
    $WOT.ID = $WOIDT
    
    $WorkerContactInformationData = New-Object MyApi.Contact_Information_Datatype
    $WorkerContactInformationData.Email_Address_Data = $Email
    
    $EmailAddressData = New-Object MyApi.Email_Address_Information_DataType
    $EmailAddressData.Email_Address = 'Nhall@EchoMichaelCharlie.Org'
    
    
    $TypeData = New-Object MyApi.Communication_Usage_Type_Datatype
    $TypeData.Primary = $true
    
    $Usage = New-Object MyApi.Communication_Method_Usage_Information_Datatype
    $Usage.Public = $true
    $EmailAddressData.Usage_Data = $Usage
    $Usage.Type_Data = $TypeData
    
    $ObjectIdType = New-Object MyApi.Communication_Usage_TypeObjectIdType
    $ObjectIdType.type = 'Communication_Usage_Type_ID'
    $ObjectIdType.Value = 'WORK'
    
    $TypeReference = New-Object MyApi.Communication_Usage_TypeObjectType
    $TypeReference.ID = $ObjectIdType
    $TypeData.Type_Reference = $TypeReference
    
    $MaintainContactInformationData = New-Object MyApi.Contact_Information_for_Person_Event_DataType
    $MaintainContactInformationData.Effective_Date = '2017-12-21'
    $MaintainContactInformationData.Worker_Reference = $WOT
    $MaintainContactInformationData.Worker_Contact_Information_Data = $WorkerContactInformationData
    
    $EventRequest1.Business_Process_Parameters = $BusinessProcessParameters
    $EventRequest1.Maintain_Contact_Information_Data = $MaintainContactInformationData
    
    # the follwoing submits the data to the server
    $webservicex.Maintain_Contact_Information($EventRequest1)
    

    This is a better match for the API but its exact usage will have to be confirmed via the web service owner.  We cannot guess at that.

    I suspect this was converted from some X# or C++ code examples but the conversion has many possible issues.

    Removing all of the "casts" should make the full error message easier to understand.  The error indicates that your data structures are not filled in correctly.


    \_(ツ)_/

    Friday, December 22, 2017 2:55 AM
  • Thank you for your swift reply! I tested your code and it give's me the same error. It seems this is more of an issue with Powershell doing the conversion then the web server responding to the request at all. However, after testing your modified code I see that it still gives the same error.

    Some of these values needs array's of specific types of structures is the correct way to define them the way I did above with

    @($MyItem)

    I appreciate the feedback!!

     

    Cannot convert argument "Maintain_Contact_Information_for_Person_Event_Request", with value: "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType", for "Maintain_Contact_Information" to type 
    "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType": "Cannot convert the "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" value of type 
    "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" to type "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType"."
    At C:\Program Files\Sentillion\proVision\Configuration\Extra\WorkdayEmail2.ps1:103 char:1
    + $webservicex.Maintain_Contact_Information($EventRequest1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    Exception             : System.Management.Automation.MethodException: Cannot convert argument "Maintain_Contact_Information_for_Person_Event_Request", with value: 
                            "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType", for "Maintain_Contact_Information" to type "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType": "Cannot convert 
                            the "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" value of type "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" to type 
                            "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType"." ---> System.Management.Automation.PSInvalidCastException: Cannot convert the 
                            "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" value of type "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType" to type 
                            "MyApi.Maintain_Contact_Information_for_Person_Event_RequestType".
                               at System.Management.Automation.LanguagePrimitives.ThrowInvalidCastException(Object valueToConvert, Type resultType)
                               at System.Management.Automation.LanguagePrimitives.ConvertNoConversion(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider 
                            formatProvider, TypeTable backupTable)
                               at CallSite.Target(Closure , CallSite , Object , Object )
                               --- End of inner exception stack trace ---
                               at System.Management.Automation.ExceptionHandlingOps.ConvertToArgumentConversionException(Exception exception, String parameterName, Object argument, String method, Type toType)
                               at CallSite.Target(Closure , CallSite , Object , Object )
                               at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                               at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                               at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    TargetObject          : 
    CategoryInfo          : NotSpecified: (:) [], MethodException
    FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
    ErrorDetails          : 
    InvocationInfo        : System.Management.Automation.InvocationInfo
    ScriptStackTrace      : at <ScriptBlock>, C:\Program Files\Sentillion\proVision\Configuration\Extra\WorkdayEmail.ps1: line 127
    PipelineIterationInfo : {}
    PSMessageDetails      : 


    PS C:\Program Files\Sentillion\proVision\Configuration\Extra> 




    Friday, December 22, 2017 4:15 PM
  • The error is because you are not using the API correctly. Contact the service vendor for help with their API.


    \_(ツ)_/

    Friday, December 22, 2017 9:12 PM
  • Hi,
    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,

    Frank

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, December 25, 2017 8:59 AM
  • Hi,
    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,

    Frank

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thanks for checking in Frank, its helpful as I am appreicated they respond but the vender returns and say's they don't have anything to do with powershell. I think my question is more geared on how to discover what the actual casting issue is. It appears the issue is partly hidden by powershell.

    Tuesday, December 26, 2017 4:49 PM
  • It is a WSDL web service.  How to use the service is documented by the vendor.  You must learn their I implementation and convert it from the vendors examples to PowerShell.  We cannot do that for you.

    In most cases the objects are not created by casting but are created by the API and AI calls.  Each service and vendor can do this in their own way.  Have the vendor tell you how to do it in C#.  C# is the easiest code to convert to PowerShell.


    \_(ツ)_/


    • Edited by jrv Tuesday, December 26, 2017 4:54 PM
    Tuesday, December 26, 2017 4:54 PM
  • It is a WSDL web service.  How to use the service is documented by the vendor.  You must learn their I implementation and convert it from the vendors examples to PowerShell.  We cannot do that for you.

    In most cases the objects are not created by casting but are created by the API and AI calls.  Each service and vendor can do this in their own way.  Have the vendor tell you how to do it in C#.  C# is the easiest code to convert to PowerShell.


    \_(ツ)_/


    Thank you JRV, I will go back to the <g class="gr_ gr_3 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="3" id="3">vender</g> with this. I figured allocating the structure correctly would be okay doing it the way I do above.
    Tuesday, December 26, 2017 5:19 PM