Here is the situation. I am a Java developer. Another developer in our company wrote a web service for our customers. They wrote a service in Java. They also recorded a demo for creating a client to use a web service in Java, and it works just fine. I was commissioned to create a web services client in VB.NET to do the same. It does not go smoothly. The problem is that the web service requires you to send the username and password to the SOAP header, and I cannot figure out how to do this on Vb.NET. I looked at the following pages:
I can not make them work. I sequentially get the “Header box with username and encrypted password” from the web service. I tried all the tips given in the previous question:
You must add the username and password to the SOAP header in the VB.NET Web Service Client
I am still getting the same error.
Here is the code I wrote.
Imports System.Net
Imports System.ServiceModel
Public Class RandomQuoteForm
Private Sub GetQuoteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetQuoteButton.Click
Dim imageService As AverittWebServices.SendWebImageClient = New AverittWebServices.SendWebImageClient("SendWebImagePort")
imageService.ClientCredentials.UserName.UserName = "apriltest11"
imageService.ClientCredentials.UserName.Password = "ew6ttRob1LY+Ik9E5oKlbA=="
Dim imageResult As String
imageResult = imageService.getAvailableImages("")
DisplayLabel.Text = imageResult
End Sub
End Class
Here's the WSDL:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="https://webservices.averittexpress.com/SendWebImageService" name="SendWebImageService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://webservices.averittexpress.com/SendWebImageService" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="https://webservices.averittexpress.com/SendWebImageService" schemaLocation="SendWebImageService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getDocument">
<part name="parameters" element="tns:getDocument"/>
</message>
<message name="getDocumentResponse">
<part name="parameters" element="tns:getDocumentResponse"/>
</message>
<message name="getAvailableImages">
<part name="parameters" element="tns:getAvailableImages"/>
</message>
<message name="getAvailableImagesResponse">
<part name="parameters" element="tns:getAvailableImagesResponse"/>
</message>
<portType name="SendWebImage">
<operation name="getDocument">
<input message="tns:getDocument"/>
<output message="tns:getDocumentResponse"/>
</operation>
<operation name="getAvailableImages">
<input message="tns:getAvailableImages"/>
<output message="tns:getAvailableImagesResponse"/>
</operation>
</portType>
<binding name="SendWebImagePortBinding" type="tns:SendWebImage">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getDocument">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getAvailableImages">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SendWebImageService">
<port name="SendWebImagePort" binding="tns:SendWebImagePortBinding">
<soap:address location="https://webservices.averittexpress.com/SendWebImageService"/>
</port>
</service>
</definitions>
Here is the diagram:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="https://webservices.averittexpress.com/SendWebImageService" xmlns:tns="https://webservices.averittexpress.com/SendWebImageService" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getAvailableImages" type="tns:getAvailableImages"/>
<xs:element name="getAvailableImagesResponse" type="tns:getAvailableImagesResponse"/>
<xs:element name="getDocument" type="tns:getDocument"/>
<xs:element name="getDocumentResponse" type="tns:getDocumentResponse"/>
<xs:complexType name="getDocument">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
<xs:element name="arg1" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getDocumentResponse">
<xs:sequence>
<xs:element name="return" type="xs:base64Binary" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getAvailableImages">
<xs:sequence>
<xs:element name="arg0" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getAvailableImagesResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
, . , VB.NET . , , , , . , - . , . , (Visual Basic Express Edition 2010) , , 100 . , , , .
"apriltest11".
"ew6ttRob1LY + Ik9E5oKlbA ==".
, getAvailableImages, : 0419151598 1022600388
WSDL , , , . . , Java-, , .
Java :
URL wsdlLocation = new URL("C:/ .../WEB-INF/wsdl/EncryptedPasswordService.wsdl");
QName qName =new QName("https://webservices.averittexpress.com/EncryptedPasswordService");
EncryptedPasswordService service = new EncryptedPasswordService(wsdlLocation,qName);
EncryptedPassword port = service.getEncryptedPasswordPort();
String encryptedPwd = port.getEncryptedPwd("username", "password");
.