Welcome Forums General PowerShell Q&A New-WebServiceProxy

Viewing 5 reply threads
  • Author
    Posts
    • #169738
      Participant
      Topics: 2
      Replies: 3
      Points: 42
      Rank: Member

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

      <wsdl:portType name=”IServerService></wsdl:portType>

      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: 406
      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: 2
      Replies: 3
      Points: 42
      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: 406
      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: 2
      Replies: 3
      Points: 42
      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)

      😉

       

    • #182298
      Participant
      Topics: 0
      Replies: 1
      Points: 10
      Rank: Member

      Hi,

      When you call New-WebServiceProxy against a wsdl with multiple interfaces, the call just creates a proxy against the first interface it finds. If you want to use other interfaces, you’ll have to declare a New-Object of the type you are actually looking to use. My typical pattern for this is this:

      $proxy = New-WebServiceProxy -Uri $url -Namespace MyNameSpace
      $proxy = New-Object MyNameSpace.IEnvSrvService
      Note that if you are using a debugger or running the script repeatedly, you will end up with namespace collisions. So in that case, I change my pattern to NOT pass in a namespace and instead get the default (ugly) one from PowerShell and reuse that.
      $proxy = New-WebServiceProxy -Uri $url
      $MyNameSpace = $proxy.GetType().Namespace
      $proxy = New-Object ("{0}.IEnvSrvService" -f $MyNameSpace)
Viewing 5 reply threads
  • The topic ‘New-WebServiceProxy’ is closed to new replies.