7

私はJAX-WSを使用してWebServiceを開発しています(jaxws-maven-pluginでwsimportゴールを使用しています)。XSDスキーマをインポートするWSDLを作成しました。

WEB-INF/wsdl/service.wsdl
WEB-INF/wsdl/service.xsd

また、Webサービスクラスを生成し、エンドポイントとすべてを作成しました。これまでのところ、すべてがうまく機能しました。Tomcat 7でサービスを実行したときは、すべて問題ありません。ブラウザで次の場所からwsdlにアクセスできます。

http://localhost:8080/webService/servlet-url?wsdl

しかし、xsdスキーマにアクセスできません。問題はこのwsdlにあります:

<xsd:schema>
<xsd:import namespace="http://ws.service/domain/1.0" schemaLocation="service.xsd"/>
</xsd:schema>

もちろん、クラスの生成中、wsdlとxsdはローカルパス上にありますが、Webサービスの実行中にリモートでアクセスできるようにしたいです。schemaLocationは「http:// localhost:8080 / webService / servlet-url?xsd=1」のようなものでなければならないことを知っています。

ブラウザに表示されるwsdlでは、インポートは次のようになります。

<xsd:schema>
    <xsd:import namespace="http://ws.service/domain/1.0" schemaLocation="http://localhost:8080/webService/servlet-url?wsdl&resource=service.xsd"/>
    </xsd:schema>

localhost:8080 / webService / servlet?wsdlは私に:

wsdl:definitions targetNamespace="http://ws.serv.com/Service/1.0" name="emuiaService">         
<wsdl:types>
    <xsd:schema>
        <xsd:import namespace="http://ws.serv.com/Service/domain/1.0" schemaLocation="schema.xsd"/>
    </xsd:schema>
</wsdl:types>
<wsdl:message name="halloMsg">
    <wsdl:part name="parameters" element="dom:halloRequest"/>
</wsdl:message>
<wsdl:message name="halloResponseMsg">
    <wsdl:part name="return" element="dom:halloResponse"/>
</wsdl:message>

等々...

4

2 に答える 2

6

これが解決するのがとても難しい問題だったとはほとんど信じられません!

私はまさにこの問題の解決策を見つけるために狂ったようにグーグルしてきました!それから私は自分で解決策を見つけるのに本当に苦労してきました。デバッガーによって-java-6-openjdkのデフォルトのjavax.xml.ws.spi.Provider実装(Webサービスの公開に使用するjavax.xml.ws.Endpointオブジェクトを作成するJREの「ファクトリー」)をステップスルーします。最終的にいくつかのことを学びました。これは、少なくともJava SEで、少なくとも現在のJREで機能するソリューションを作成するのに役立ちました。

java version "1.6.0_33"
OpenJDK Runtime Environment (IcedTea6 1.13.5) (6b33-1.13.5-1ubuntu0.12.04)
OpenJDK Server VM (build 23.25-b01, mixed mode)

このソリューションがJavaEEで使用できるかどうかは、まだわかりません。

これが私がそれを解決した方法です:

package myservice;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.Endpoint;

public class App 
{
    private static final String MY_SERVICE_XSD = "/wsdl/MyService.xsd";

    public static void main( String[] args )
    {
        Endpoint ep = Endpoint.create(new MyEndpointImpl());

        ep.setMetadata(Arrays.asList(sourceFromResource(MY_SERVICE_XSD)));

        ep.publish("http://localhost:8080/svc/hello");
    }

    private static Source sourceFromResource(String name) {
        URL resource = App.class.getResource(name);
        String systemId = resource.toExternalForm();
        InputStream inputStream;
        try {
            inputStream = resource.openStream();
        } catch (IOException e) {
            throw new RuntimeException("Failed to create InputStream from resource \""+ name +"\"", e);
        }
        return new StreamSource(inputStream, systemId);
    }
}

重要なことは、最初にメソッドEndpoint#create(Endpoint#publishではなく)を使用して、未公開のEndpointを取得することです。次に、XSDファイルを「メタデータ」として(まだ公開されていない)エンドポイントに追加します(コード「ep.setMetaData(...)」)。次に、エンドポイントを公開します(コード "ep.publish(...)")。

アクセスすると、次のようhttp://localhost:8080/svc/hello?wsdlになります。

    <definitions targetNamespace="http://somewhere.net/my/namespace" name="MyService">
        <types>
            <xsd:schema>
                <xsd:import namespace="http://somewhere.net/my/namespace"
                            schemaLocation="http://localhost:8080/svc/hello?xsd=1"/>
            </xsd:schema>
        </types>
                  ...
    </definitions>

私のXSDファイルはhttp://localhost:8080/svc/hello?xsd=1!から入手できます。

ディスク上のMyService.wsdlファイルにはまだ次のものが含まれていることに注意してください。

            <xsd:schema>
                <xsd:import namespace="http://somewhere.net/my/namespace"
                            schemaLocation="MyService.xsd"></xsd:import>
            </xsd:schema>
于 2014-12-02T14:05:28.417 に答える
0

さて、ここに行きます。

このようなものを変更するためにWSDLファイルに

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wsdl:definitions
      targetNamespace="http://service.wsr.company.com/" 
      name="webServiceExample" 
      xmlns="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:tns="http://servicio.wsr.baz.com/" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

この小さなスニペットで重要なのはxmlnsタグです。これらは、スキーマXSDの展開に役立ちます。次

<wsdl:types>
    <xs:schema 
        xmlns:tns="http://service.wsr.company.com/" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://service.wsr.company.com/" version="1.0">

        ...

    </xs:schema>
</wsdl:types>

service.xsd以下のタグに、ファイルにあるものを取得するか、http://localhost:8080/webService/servlet-url?xsd=1続行して表示します

    <wsdl:message name="your_method_name">
         <wsdl:part name="parameters" element="tns:your_method_name"/>
    </wsdl:message>
    <wsdl:message name="your_method_nameResponse">
         <wsdl:part name="parameters" element="tns:your_method_nameResponse"/>
    </wsdl:message>

上記のタグはメソッド名を示しています。次

    <wsdl:portType name="webServiceExample">
          <wsdl:operation name="your_method_name">
            <wsdl:input message="tns:your_method_name"/>
              <wsdl:output message="tns:your_method_nameResponse"/>
          </wsdl:operation>
    </wsdl:portType>

上記のtarは、操作を行うためのものです。継続する

    <wsdl:binding name="webServiceExamplePortBinding" type="tns:webServiceExample">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="your_method_name">
          <soap:operation soapAction=""/>
            <wsdl:input>
              <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
              <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

次の :)

   <wsdl:service name="webServiceExample">
     <wsdl:port name="webServiceExamplePort" binding="tns:webServiceExamplePortBinding">
       <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</wsdl:port>

そして最後に終了しました:)

現在のタグをタグごとに変更する必要があることに注意してください <wsdl:...></wsdl:...>

それを保存すると、パブリックになり、楽しいXSDスキーマがWSDLに表示されます

お役に立てば幸いです。チャオ。

于 2012-06-16T22:42:03.563 に答える