开发者

Getting a response with a VB.NET client from a Java Web Service

Here's the situation. I'm a Java developer. Another developer in our company wrote a web service for our clients. They wrote the service in Java. They also wrote a demo for creating a client to consume the web service in Java and it works just fine. I've been tasked with creating a web services client in VB.NET to do the same thing. It hasn't been going smoothly. The problem is that the web service requires that you send the username and password in the SOAP header and I can't figure out how to do that in Vb.NET. I looked at the following pages:

  • http://msdn.microsoft.com/en-us/library/system.servicemodel.httptransportsecurity.aspx
  • http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpsecurity.aspx
  • http://msdn.microsoft.com/en-us/library/ms553830.aspx

I can't get any of them to work. I consistently get "Soap Header with UserName and encrypted Password is missing" from the web service. I've tried all the advice given in a previous question:

Need to add username and password to SOAP header in VB.NET Web Service Client

I'm still getting the same error.

Here's the code I've written.

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"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->
<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="Sen开发者_JS百科dWebImageService">
    <port name="SendWebImagePort" binding="tns:SendWebImagePortBinding">
      <soap:address location="https://webservices.averittexpress.com/SendWebImageService"/>
    </port>
  </service>
</definitions>

Here's the schema:

<?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>

I've spent over 3 whole days trying to get this to work. I have no doubt that a VB.NET developer could kick this thing out post haste. I'm just not that developer and truthfully I've got other things I'd like to work on. I've come to the point where I'm willing to try something a little different. So, here's the deal. To the first developer to post an answer to this question with code I can get to work on my laptop (Visual Basic Express Edition 2010) and any explanation needed to get it to work, I will donate $100 to the charity of their choice. It's not a world changing amount but most charities I know would appreciate the thought.

The username needs to be "apriltest11". The encrypted password needs to be "ew6ttRob1LY+Ik9E5oKlbA==". Valid arguments that you can pass to the getAvailableImages method are: 0419151598 and 1022600388

The WSDL is publicly available and the username/password combo are only for testing so don't feel like I'm giving away the keys to the kingdom here. I would love to get an answer to this. Not only would I be able to go back to my normal Java project, at this point I'd actually like to see how this is done.

Java Code for setting the username and password:

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");

Thanks.


Is your Java web service publish metadata properly. If so I believe you can right click in visual studio solution explorer and add web reference which will create the proxy for you.

This will work out only if you use Visual studio. I dont know whether Java developers like ot or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜