使用 wsdl 和 axis2 生成 ws 客户端

generate ws client with wsdl and axis2

我有这个wsdl

<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-hudson-48-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-hudson-48-. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice.consulta.spcjava.spcbrasil.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webservice.consulta.spcjava.spcbrasil.org/" name="consultaWebService">
<types>
<xsd:schema>
<xsd:import namespace="http://webservice.consulta.spcjava.spcbrasil.org/" schemaLocation="https://servicos.spc.org.br:443/spc/remoting/ws/consulta/consultaWebService?xsd=1" />
</xsd:schema>
</types>
<message name="consultar">
<part name="filtro" element="tns:filtro" />
</message>
<message name="consultarResponse">
<part name="resultado" element="tns:resultado" />
</message>
<message name="listarProdutos" />
<message name="listarProdutosResponse">
<part name="produtos" element="tns:produtos" />
</message>
<message name="detalharProduto">
<part name="codigo-produto" element="tns:codigo-produto" />
</message>
<message name="detalharProdutoResponse">
<part name="produto" element="tns:produto" />
</message>
<portType name="consultaWebService">
<operation name="consultar">
<input message="tns:consultar" />
<output message="tns:consultarResponse" />
</operation>
<operation name="listarProdutos">
<input message="tns:listarProdutos" />
<output message="tns:listarProdutosResponse" />
</operation>
<operation name="detalharProduto">
<input message="tns:detalharProduto" />
<output message="tns:detalharProdutoResponse" />
</operation>
</portType>
<binding name="consultaWebServicePortBinding" type="tns:consultaWebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="consultar">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
<operation name="listarProdutos">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
<operation name="detalharProduto">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="consultaWebService">
<port name="consultaWebServicePort" binding="tns:consultaWebServicePortBinding">
<soap:address location="https://servicos.spc.org.br:443/spc/remoting/ws/consulta/consultaWebService" />
</port>
</service>
</definitions>

当我使用 axis2 生成 wsdl 时出现错误

Exception occurred during code generation for WSDL : org.apache.axis2.AxisFault: WSDLException (at /definitions/types/xsd:schema): faultCode=OTHER_ERROR: An error occurred trying to resolve schema referenced at 'https://servicos.spc.org.br:443/spc/remoting/ws/consulta/consultaWebService?xsd=1', relative to 'file:/C:/Users/Tiago Roque/workspace/spe/WebContent/WEB-INF/ws/consultaWebService.xml.wsdl'.: java.io.IOException: Server returned HTTP response code: 401 for URL: https://servicos.spc.org.br:443/spc/remoting/ws/consulta/consultaWebService?xsd=1

我使用eclipse生成 有人可以帮助我吗?

wsdl 引用受访问保护的外部 xml-schema(参见 xsd:import)。这就是您收到 401 (UNAUTHORIZED) 错误 (https://servicos.spc.org.br:443/spc/remoting/ws/consulta/consultaWebService?xsd=1) 的原因。

也许您可以请求 wsdl 的内联版本(其中所有模式定义都内联在一个完整的 wsdl 中)。