Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, November 20, 2018 7:29 PM
Hi,
I've managed to query many web services from PowerShell but this one is throwing me.
I can access it through SOAPUI but its gives us two interfaces with the prefix of basicHttpBinding_XXXXXX
When I connect using
New-WebServiceProxy -Uri "http://XXXXXXX?Wsdl"
I connect to the wrong interface and can see the methods available to it.
How do I specify which interface to connect to?
All replies (11)
Wednesday, November 28, 2018 1:34 PM ✅Answered
Just an example. You have to find out from the service what the endpoint is. That is what you are missing.
The service requires authentication. Before you can connect you must authenticate. The WSDL generates the proxy.
In IE you can enter the Uri and see the WSDL definition. There cannot be two services on one Uri.
On some services the unauthenticated connection will connect to a test site that is used to verify the connection without authentication. Authentication normally causes the connection to access the full service.
None of this has anything to do with scripting.. It is about how web services work. In C# you don't have the CmdLets so you have to write all of the code. You can use WCF, WebRequest or XML/Soap to access the service. In PowerShell this is all packaged for you.
Authentication is handled using standard methods with New-WebProxy. Some web services my require custom headers. This can only be determined by contacting the web service provider although services that use the WSDL web interface usually use standard methods without any custom headers.
You may also need to use HTTPS for you connection. Most services that require authentication require HTTPS.
\(ツ)_/
Tuesday, November 20, 2018 7:41 PM
You must use the correct name for the service you are connecting to.
New-WebServiceProxy -Uri http://service.domain.com?Wsdl
Try it with the browser first. You should get the WSDL page for the service.
What is it you are calling an "interface". Are you saying the system has two IP addresses?
\(ツ)_/
Tuesday, November 20, 2018 8:28 PM
I can connect to the web service and can see the methods I want to use.
However, I keep connecting to the wrong WSDL interface I think is the term.
When I connect using SOAPUI there are two WSDL interfaces and I can use "Show Interface Viewer" on each
When I expand the second one it has the methods I'm after.
How do I get PowerShell to access it?
Tuesday, November 20, 2018 8:44 PM
WSDL is not an interface it is the service. When you connect an object is created that represents the service and you call methods and access properties on the service through the "proxy" object.
The GUI is not what is important with net services when using PowerShell.
To learn how to use Amazon web services post in the Amazon developer forum. They will help you sort this out.
You likely need to specify a different URI for each service in the set. I don't remember how AWS set this up in the designer but one of the options (Add IMS Endpoint?) sets the endpoint that you connect to.
\(ツ)_/
Tuesday, November 20, 2018 10:21 PM
I see. I'm not using a AWS web service, that was just an example.
In SOAPUI I can see there are two bindings on the same WSDL URL.
Beneath each binding are the methods I want to use.
How can I specify in PowerShell which binding to use?
How does the -class parameter work?
Tuesday, November 20, 2018 10:46 PM
Are you saying that there are two WSDL documents on one URI? I don't think so.
\(ツ)_/
Wednesday, November 21, 2018 7:17 AM
Hi,
If you have some questions about how to use "New-WebServiceProxy" cmdlet.
Please refer the link below:
/en-us/powershell/module/microsoft.powershell.management/new-webserviceproxy?view=powershell-5.1
Best Regards,
Lee
Just do it.
Tuesday, November 27, 2018 2:52 AM
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
LEE
Just do it.
Wednesday, November 28, 2018 9:09 AM
Hi,
I've made some progress with this.
It seems that I'm trying to query a WCF that is using NetTCPBinding instead of HTTP.
Anyway I followed the instructions and used the svcutil.exe to generate a proxy code then the C# compiler CSC.exe to build it into a DLL file.
Loaded the DLL into PowerShell using Add-Type and now I can connect to the right endpoint and access the methods I want. The code below helped me connect:
# Generate the proxy code
svcutil.exe http://localhost:55028/Service1.svc?wsdl
# Build the proxy DLL
csc /t:library .\Service1.cs
# Load the DLL
Add-Type -Path .\Service1.dll
$binding = new-object System.ServiceModel.BasicHttpBinding
$endpoint = new-object System.ServiceModel.EndpointAddress(“http://localhost:55028/Service1.svc")
# Create an instance of the client
$client = New-Object Service1Client($binding, $endpoint)
# Call a method using your client
$client.GetData(4)
However, I need to pass credentials into it and haven't figured out that bit. When I call the method I get the error
"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm=""'."
Any suggestions where to look?
I've managed to connect to the endpoint and login and submit requests using SOAP UI, its just trying to replicate the same process in PowerShell.
Wednesday, November 28, 2018 9:26 AM
$cred= Get-Credential
$proxy = New-WebServiceProxy http://localhost:55028/Service1.svc?wsdl -Credential $cred
\(ツ)_/
Wednesday, November 28, 2018 12:44 PM
I'm afraid this binds to the wrong endpoint