java 从 WSDL 创建 Web 服务的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1924005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:32:54  来源:igfitidea点击:

Problem creating a web service from a WSDL

javaweb-serviceswsdlnetbeans6.8

提问by ChadNC

The problem I'm having is that when I attempt to create a web service in netbeans using this wsdl, netbeans says that there is no service defined. I'm new to the whole wsdl thing but as far as I can tell there is one defined.

我遇到的问题是,当我尝试使用此 wsdl 在 netbeans 中创建 Web 服务时,netbeans 说没有定义服务。我是整个 wsdl 的新手,但据我所知,已经定义了一个。

The wsdl is:

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 says that the wsdl is valid but it fails when i try to create the web service from it. Any help would be appreciated even constructive criticism.

XMLSpy 说 wsdl 是有效的,但是当我尝试从中创建 Web 服务时它失败了。任何帮助将不胜感激,即使是建设性的批评。

EDIT

编辑

Using wsimport from the commmand line I get.

从我得到的命令行使用 wsimport。

[ERROR] Invalid wsdl:operation "RequestQuote": its a rpc-literal operation, mes sage part must refer to a schema type declaration line 16 of file:/D:/projects/DICACORD/QuoteRq2.wsdl

[错误] 无效的 wsdl:operation "RequestQuote": 它是一个 rpc-literal 操作,消息部分必须引用文件的模式类型声明第 16 行:/D:/projects/DICACORD/QuoteRq2.wsdl

Does that mean that even though the two xsd's are imported I still have to define the types in the wsdl?

这是否意味着即使导入了两个 xsd,我仍然必须在 wsdl 中定义类型?

Update 2

更新 2

The schema for the request->. Schema at pastie

请求的架构->。 馅饼的架构

Addition

添加

Does anyone see anything wrong with the xsd imports and/or how they are being used?

有没有人看到 xsd 导入和/或它们的使用方式有什么问题?

采纳答案by ChadNC

To answer my own question, the reason the web service was failing to be created from the wsdl was due to the use ofwsdl:importinstead of xs:import.

为了回答我自己的问题,无法从 wsdl 创建 Web 服务的原因是使用wsdl:importxs:import.

I didn't know it but after doing some more research it seems that wsdl:import should be used when you want to import another wsdl but if you want to import a schema from a to use the types defined in it within the wsdl you need to use an xsd:importbecause if not wsimport will not find the types defined in the schema.

我不知道,但在做了更多的研究之后,当您想导入另一个 wsdl 时,似乎应该使用 wsdl:import 但如果您想从 a 导入模式以使用您需要的 wsdl 中定义的类型使用,xsd:import因为如果没有 wsimport 将找不到模式中定义的类型。

I changed

我变了

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"

to

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

and changed the imports from

并改变了进口

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

to

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

Making these changes allowed the web service to build successfully and the classes were created based off of the two schemas. Hopefully when I begin testing the web service on Monday it will work as I want it to. Thanks all of you for the input you provided as it led me to look into other reasons why the creation of the web service from the wsdl was failing.

进行这些更改使 Web 服务能够成功构建,并且基于这两个模式创建了类。希望当我在星期一开始测试 Web 服务时,它会按我希望的那样工作。感谢大家提供的意见,因为它让我调查了从 wsdl 创建 Web 服务失败的其他原因。

I did change the namespace that they are in but that was for different reasons and I did that after the web service had been created and deployed locally on my machine.

我确实更改了它们所在的命名空间,但这是出于不同的原因,并且在我的机器上本地创建并部署了 Web 服务之后,我才这样做了。

Happy Holidays Everyone.

祝大家节日快乐。

回答by maximdim

Easiest way to verify that wsdl is valid is to run from command line:

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

wsimport yourservice.wsdl

and see if it gives you any errors. wsimport comes with JDK 1.6

看看它是否给你任何错误。wsimport 随 JDK 1.6 一起提供

WSDL you submitted is not complete as it has references to external schema files (XSD) so there is no way for me to validate it.

您提交的 WSDL 不完整,因为它引用了外部架构文件 (XSD),因此我无法对其进行验证。

回答by Noel Ang

ACORD is in the namespace http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRq.xsd.

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

It seems to me that your import of ACORD is invalid, in that it is identifying ACORD's namespace differently:

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

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

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