wsimport未连接到主机的Java Web服务客户端

时间:2011-03-18 13:23:42

标签: java web-services webservice-client wsimport

我正在为Cognos开发自定义身份验证提供程序。我们有一个web服务,它将监听auth请求。出于测试目的,我只是尝试发送用户/通行证(稍后将更改以使用会话信息)。

在实现自定义提供程序之前,我一直在尝试让POC在简单的Java控制台应用程序中运行。我无法让客户端与Web服务进行通信。我使用wsimport使用keep标志生成我的类。我将生成的java文件放入我的Eclipse项目中并构建了一个类似于main的方法:

CognosAuthentication service = new CognosAuthentication();

CognosAuthenticationSoap soapClient = service.getCognosAuthenticationSoap();

CognosUser user = soapClient.validateDevSession("username", "password");

System.out.println(user == null ? "User was null" : user.getUserName());

我已经尝试过指定服务的URL(两端都附加'?wsdl'而不是):

CognosAuthentication service = new CognosAuthentication(new URL("http://somehost/CognosAuthentication.asmx"), new QName("http://tempuri.org/", "CognosAuthentication"));

服务生成的WSDL在哪里:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s1="http://www.ourcompany.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:import namespace="http://www.ourcompany.com/" />
      <s:element name="ValidateSession">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="expires" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="userId" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="authToken" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ValidateSessionResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" ref="s1:ValidateSessionResult" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ValidateDevSession">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ValidateDevSessionResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" ref="s1:ValidateDevSessionResult" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.ourcompany.com/">
      <s:element name="ValidateSessionResult" nillable="true" type="s1:CognosUser" />
      <s:complexType name="CognosUser">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="CognosSlot" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="GroupName" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string" />
        </s:sequence>
      </s:complexType>
      <s:element name="ValidateDevSessionResult" nillable="true" type="s1:CognosUser" />
    </s:schema>
  </wsdl:types>
  <wsdl:message name="ValidateSessionSoapIn">
    <wsdl:part name="parameters" element="tns:ValidateSession" />
  </wsdl:message>
  <wsdl:message name="ValidateSessionSoapOut">
    <wsdl:part name="parameters" element="tns:ValidateSessionResponse" />
  </wsdl:message>
  <wsdl:message name="ValidateDevSessionSoapIn">
    <wsdl:part name="parameters" element="tns:ValidateDevSession" />
  </wsdl:message>
  <wsdl:message name="ValidateDevSessionSoapOut">
    <wsdl:part name="parameters" element="tns:ValidateDevSessionResponse" />
  </wsdl:message>
  <wsdl:portType name="CognosAuthenticationSoap">
    <wsdl:operation name="ValidateSession">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Gets user information based on the authentication token</wsdl:documentation>
      <wsdl:input message="tns:ValidateSessionSoapIn" />
      <wsdl:output message="tns:ValidateSessionSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="ValidateDevSession">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Gets user information based on the authentication token</wsdl:documentation>
      <wsdl:input message="tns:ValidateDevSessionSoapIn" />
      <wsdl:output message="tns:ValidateDevSessionSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="CognosAuthenticationSoap" type="tns:CognosAuthenticationSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ValidateSession">
      <soap:operation soapAction="http://tempuri.org/ValidateSession" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="ValidateDevSession">
      <soap:operation soapAction="http://tempuri.org/ValidDevSession" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="CognosAuthenticationSoap12" type="tns:CognosAuthenticationSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ValidateSession">
      <soap12:operation soapAction="http://tempuri.org/ValidateSession" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="ValidateDevSession">
      <soap12:operation soapAction="http://tempuri.org/ValidDevSession" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="CognosAuthentication">
    <wsdl:port name="CognosAuthenticationSoap" binding="tns:CognosAuthenticationSoap">
      <soap:address location="http://mbeard2/LMS/app/analytics/CognosAuthentication.asmx" />
    </wsdl:port>
    <wsdl:port name="CognosAuthenticationSoap12" binding="tns:CognosAuthenticationSoap12">
      <soap12:address location="http://mbeard2/LMS/app/analytics/CognosAuthentication.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我假设我已经使用wsimport完成了所有正确的步骤。我面临的问题是它永远不会 。我可以启动提琴手并观察没有网络流量发生。 用户对象始终为null。我需要配置什么吗? Web服务是C#/ ASP.NET服务有什么奇怪的吗?我是否遗漏了我使用SOAP请求结构的方法?

我在编译期间或运行代码时没有收到任何错误。我正在挠头寻找答案!

1 个答案:

答案 0 :(得分:0)

因此需要“关闭我的问题因为我是个笨蛋”选项。不知何故,提琴手没有接受请求。我得到了一个连接到webservice的远程调试,看到请求进来并因为我输错密码而被踢出去。哦,好吧......