New-WebServiceProxy

Welcome Forums General PowerShell Q&A New-WebServiceProxy

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #169738

    Participant
    Topics: 1
    Replies: 3
    Points: 31
    Rank: Member

    I am trying to hit a soap service with the following ports

     name="IServerService">...

    I believe my issue is in understanding the ins and out of what a class or a namespace is within a wsdl.

    if I use $request=New-WebServiceProxy -Uri $url and try to use a function from any Service other than IApplicationService no functions show up.  I understand I should be able to use class or namespace to switch ports but I'm not having any luck.  Most of the documentation on New-WebServiceProxy point to outdated public wsdl's. Is there any documentation that uses updated public api's? Or anyone who has experience with using new-webservice proxy and making soap calls?

  • #169792

    Participant
    Topics: 4
    Replies: 54
    Points: 382
    Helping Hand
    Rank: Contributor

    Depends on the Soap you want to access,

    If i go to our soap server ill have to do the following

    
    $VerbosePreference = "Continue"
    
    $URI = 'https://servername:8099/SOAP?service=Map2Max'
    
    $Soap = New-WebServiceProxy -Uri $URI
    $token = $null
    $login = $soap.login([string]'loginname', [string]'password', [ref]$Token)
    
    if ($login.Result -eq $true) {
    Write-Verbose 'Inloggen gelukt'
    $soap.GetConnectionString($token, 'loginname')
    $logoff = $soap.LogOff($token)
    #($soap.LogOff($token).Resultmsg) #short notation
    $logoff.Resultmsg
    }
    else {
    Write-Verbose 'Inloggen niet gelukt'
    }
    
    

     

    If you want more examples let me know

  • #169954

    Participant
    Topics: 1
    Replies: 3
    Points: 31
    Rank: Member

    thank you.

    If I have the following soap service http://[address]/Service1.svc?wsdl

    With the following structure (trimmed down for the purpose of this forum)
    -p class="line">-/p>
    I could not get the xml pasting to work here so going rogue and replace all the carrots with dashes in the xml below.

    
    -wsdl:message name="IApplicationService_ApplicationDetailsbyAppID_InputMessage">
    -wsdl:part name="parameters" element="tns:ApplicationDetailsbyAppID"/>
    -/wsdl:message>
    ....
    -wsdl:message name="IServerService_ServerDetailsbyServerID_OutputMessage">
    -wsdl:part name="parameters" element="tns:ServerDetailsbyServerIDResponse"/>
    -/wsdl:message>
    ....
    -wsdl:portType name="IApplicationService">
    -wsdl:operation name="ApplicationDetailsbyAppID">
    -wsdl:input wsaw:Action="http://tempuri.org/IApplicationService/ApplicationDetailsbyAppID" message="tns:IApplicationService_ApplicationDetailsbyAppID_InputMessage"/>
    -wsdl:output wsaw:Action="http://tempuri.org/IApplicationService/ApplicationDetailsbyAppIDResponse" message="tns:IApplicationService_ApplicationDetailsbyAppID_OutputMessage"/>
    -/wsdl:operation>
    ...
    -/wsdl:portType>
    -wsdl:portType name="IServerService">
    -wsdl:operation name="ServerDetailsbyServerID">
    -wsdl:input wsaw:Action="http://tempuri.org/IServerService/ServerDetailsbyServerID" message="tns:IServerService_ServerDetailsbyServerID_InputMessage"/>
    -wsdl:output wsaw:Action="http://tempuri.org/IServerService/ServerDetailsbyServerIDResponse" message="tns:IServerService_ServerDetailsbyServerID_OutputMessage"/>
    -/wsdl:operation>
    ...
    -/wsdl:portType>
    -wsdl:binding name="BasicHttpBinding_IApplicationService" type="tns:IApplicationService">
    -soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    -wsdl:operation name="ApplicationDetailsbyAppID">
    -soap:operation soapAction="http://tempuri.org/IApplicationService/ApplicationDetailsbyAppID" style="document"/>
    -wsdl:input>
    -soap:body use="literal"/>
    -/wsdl:input>
    -wsdl:output>
    -soap:body use="literal"/>
    -/wsdl:output>
    -/wsdl:operation>
    -wsdl:binding name="BasicHttpBinding_IServerService" type="tns:IServerService">
    -soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    -wsdl:operation name="ServerDetailsbyServerID">
    -soap:operation soapAction="http://tempuri.org/IServerService/ServerDetailsbyServerID" style="document"/>
    -wsdl:input>
    -soap:body use="literal"/>
    -/wsdl:input>
    -wsdl:output>
    -soap:body use="literal"/>
    -/wsdl:output>
    -/wsdl:operation>
    
    

    -p class="line">I then use the following powershell to get to the wsdl-/p>

    $url="http://[address]/Service1.svc?wsdl"
    $y=New-webServiceProxy -Uri $url
    
    $y.ServerDetailsbyServerID(10,1)
    
    

    I get this error:

    
    Method invocation failed because [Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy11caqa_corpadqa_net_Service1_svc.BasicHttpBinding_IApplicationService]
    does not contain a method named 'ServerDetailsbyServerID'.
    At line:5 char:1
    + $y.ServerDetailsbyServerID(10,1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
    
    

    It only sees functions from iapplicationservice. Which makes no sense. SoapUI can crawl the entire service. Thank you. I am assuming their is something within the namespace or class functions I am missing.   I've tried adding Iserverservice as a paramater for one then the other and both and got a similar result.  I offer up that maybe I do not understand API's that well.  Thank you.thank you.

  • #169990

    Participant
    Topics: 4
    Replies: 54
    Points: 382
    Helping Hand
    Rank: Contributor

    without the link to the wsdl all i can think of is something like

     

    $y.IServerService.ServerDetailsbyServerID(10,1)

  • #170014

    Participant
    Topics: 1
    Replies: 3
    Points: 31
    Rank: Member

    Sadly it is internal. Tried that and it get's me "You cannot call a method on a null-valued expression." which seems to be a little promising. Frustrating in it's own way I got this working with

    invoke-webrequest

    
    $URI = "http://address/Service1.svc?WSDL"
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("charset", 'utf-8')
    $headers.Add("SOAPAction", 'urn:WatchmanService:ServersService/IServerService/ServerDetailsbyServerID')
    
    [xml] $body=@"
    -soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:WatchmanService:ServersService"-
    -soapenv:Header/-
    -soapenv:Body-
    -urn:ServerDetailsbyServerID-
    -!–Optional:—
    -urn:ServerID-10-/urn:ServerID-
    -/urn:ServerDetailsbyServerID-
    -/soapenv:Body-
    -/soapenv:Envelope-
    "@
    
    [xml] $result = (Invoke-WebRequest -Method Post -Uri $URI -Headers $headers -Body $body -ContentType 'text/xml')
    $result.InnerXml
    
    

     

    Any thoughts on translating that to New-WebServiceProxy?  (honestly, it's now an ego thing)

    😉

     

You must be logged in to reply to this topic.