从WSDL创建Web服务的问题

3

我遇到的问题是,当我尝试使用这个wsdl在netbeans中创建web服务时,netbeans会提示没有定义服务。我对wsdl还不太了解,但据我所知应该已经定义好了一个服务。

这个wsdl内容如下:

 <?xml version="1.0" encoding="UTF-8"?>
 <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://discoveryinsurance.com/DicQuoteSvc/AgencyQuote.wsdl" xmlns:ns="http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRq.xsd" xmlns:na="http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRs.xsd" targetNamespace="http://discoveryinsurance.com/DicQuoteSvc/AgencyQuote.wsdl">
<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" location="DicAcordQuoteRq.xsd"/>
<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" location="DicAcordQuoteRs.xsd"/>
<wsdl:types>
    <xs:schema targetNamespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" elementFormDefault="qualified"/>
</wsdl:types>
<wsdl:message name="NewMessageRequest">
    <wsdl:part name="parameter" element="ns:ACORD"/>
</wsdl:message>
<wsdl:message name="NewMessageResponse">
    <wsdl:part name="parameter" element="na:ACORD"/>
</wsdl:message>
<wsdl:portType name="QuotePortType">
    <wsdl:operation name="RequestQuote">
        <wsdl:input message="tns:NewMessageRequest"/>
        <wsdl:output message="tns:NewMessageResponse"/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="QuoteBinding" type="tns:QuotePortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="RequestQuote">
        <soap:operation soapAction="http://discoveryinsurance.com/DicQuoteSvc/AgencyQuote" style="rpc"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="AgencyQuote">
    <wsdl:port name="QuotePortType" binding="tns:QuoteBinding">
        <soap:address  location="http://discoveryinsurance.com/DicQuoteSvc/"/>
    </wsdl:port>
</wsdl:service>

XMLSpy表示WSDL有效,但在我尝试从中创建Web服务时失败了。 任何帮助都将不胜感激,包括建设性的批评。
编辑: 使用命令行中的wsimport,我得到以下错误信息。 “无效的wsdl:操作“RequestQuote”:它是一个rpc-literal操作,消息部分必须引用模式类型声明 文件:/D:/projects/DICACORD/QuoteRq2.wsdl的第16行” 这是否意味着即使导入了两个xsd,我仍然必须在wsdl中定义类型?
更新2: 请求的架构->。 过去的架构请参阅 补充: 有人看到xsd导入或使用方式有问题吗?

这些模式已经超过了250行。它能允许我发布这么大的吗? - ChadNC
嗯...使用Spring是一个选项吗?如果是的话,我可以指向一个问题,展示整个设置。我也可以指向一个教程... Spring非常棒,因为它会即时为您生成WSDL。 - Zoidberg
1
@Zoidberg,别开玩笑了,Spring 在这里解决不了任何问题。这不是一个 WS 栈的问题...而且有些人确实想要使用 WSDL-first 方法(JAX-WS 也可以生成 WSDL)。 - Pascal Thivent
很不幸,对于这个特定的项目来说,Spring 不是一个选择。 - ChadNC
我从xmlspy中复制/粘贴了模式。我不知道为什么它会添加这么多制表符。 - ChadNC
显示剩余4条评论
3个回答

5

验证wsdl文件是否有效的最简单方法是从命令行运行:

wsimport yourservice.wsdl

请尝试运行并查看是否出现错误。wsimport随JDK 1.6一起提供。

您提交的WSDL不完整,因为它引用外部模式文件(XSD),所以我无法验证它。


1
为了回答自己的问题,Web服务无法从wsdl创建的原因是由于使用了wsdl:import而不是xs:import
我之前并不知道,但经过更多的研究后发现,当您想要导入另一个wsdl时,应该使用wsdl:import,但如果您想要导入模式以在wsdl中使用其中定义的类型,则需要使用,否则wsimport将无法找到模式中定义的类型。
我进行了修改。
xmlns:ns="http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRq.xsd"
xmlns:na="http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRs.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns:rq="http://discoveryinsurance.com/DicQuoteSvc/schemas/request/" 
xmlns:rs="http://discoveryinsurance.com/DicQuoteSvc/schemas/response/"

并且已经更改了导入方式

<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/"  location="DicAcordQuoteRq.xsd"/>
<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" location="DicAcordQuoteRs.xsd"/>

<xs:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/request/" schemaLocation="DicAcordQuoteRq.xsd"/>
<xs:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/response/" schemaLocation="DicAcordQuoteRs.xsd"/>

进行这些更改使 Web 服务能够成功构建,类是基于这两个模式创建的。希望当我在星期一开始测试网络服务时,它能像我想要的那样工作。感谢你们所有人提供的意见,因为它让我去探究 wsdl 创建网络服务失败的其他原因。
我确实更改了它们所在的命名空间,但那是出于不同的原因,在 Web 服务被创建并在我的机器上部署后才这么做。
祝大家节日快乐。

0

ACORD位于命名空间http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRq.xsd中。

在我看来,您导入ACORD的方式是无效的,因为它以不同的方式标识了ACORD的命名空间:

<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" location="DicAcordQuoteRq.xsd"/>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接