2012-06-13 29 views
7

JAX-WS ile WebService geliştiriyorum (jaxws-maven-plugin üzerinde wsimport hedefi kullanıyorum). Bir XSD şemasını ithal eden bir WSDL yazdım. Ayrıca, web hizmeti sınıfları oluşturdum ve son nokta ve her şeyi oluşturdum. Her şey şimdiye kadar çok çalıştı. Tomcat 7'de hizmetimi çalıştırdığımda her şey yolunda. Ben benim tarayıcıda bir wsdl erişebilir:xsd şema wsdl tarafından sunulmadı

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

ama Xsd şema erişim elde edilemez. sınıflar wsdl ve xsd oluşturma sırasında

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

yerel yoldayız ama web hizmeti çalışırken onları uzaktan erişilebilir olmasını istiyorum: Sorun bu wsdl içindedir. SchemaLocation'ın "http: // localhost: 8080/webService/servlet-url? Xsd = 1" gibi bir şey olması gerektiğini biliyorum.

<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 bana verir:? Vb

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> 

ve ...

cevap

4

Bu sorunun çözülmesi zor bir problem olduğuna neredeyse inanamıyorum!

Tam olarak bu soruna çözüm bulmak için deli gibi dolaşmaya başladım! Sonra kendi başıma bir çözüm bulmak için çok uğraştım. Java-6-openjdk'in varsayılan javax.xml.ws.spi.Provider uygulamasında hata ayıklayıcısına (JRE'deki "fabrika"), javax.xml.ws.Endpoint nesnelerini web hizmetleri yayınlamak için kullandığınız nesneler oluşturur. nihayet en azından benim şimdiki JRE, en azından, Java SE çalışan bir çözüm zanaat bana yardımcı olan bazı şeyler öğrendim: bu çözüm Java EE kullanılabilecek olan

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) 

olsun bilmiyorum henüz. İşte

ben onu çözdüm nasıl:

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); 
    } 
} 

önemli şey ilk kullanım yöntemi Endpoint # yaratmak olduğunu bir yayınlanmamış Endpoint almak için (Endpoint değil # yayımlamak). Sonra XSD dosyasını (hala basılmamış) Bitiş Noktası'na (meta "ep.setMetaData (...)") "meta veri" olarak ekliyorum. O zaman Son noktayı yayınlarım (kod "ep.publish (...)"). Ben http://localhost:8080/svc/hello?wsdl eriştiklerinde

Şimdi alıyorum:

<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> 

ve benim XSD dosyası http://localhost:8080/svc/hello?xsd=1 edinilebilir! diskte benim MyService.wsdl dosyası hala içeriyor

Not:

  <xsd:schema> 
       <xsd:import namespace="http://somewhere.net/my/namespace" 
          schemaLocation="MyService.xsd"></xsd:import> 
      </xsd:schema> 
+0

Gerçekten ne yaptığımı hatırlamıyorum ... muhtemelen son sözleşmeye geçtiniz ama çözdüğünüz için teşekkürler. Umarım birgün birisine yardım eder;) – bemol

0

benziyor schould tarayıcı ithalat sunulan wsdl olarak

Tamam, işte başlıyoruz. WSDL dosyası içine

önemli xmlns etiketi olan bu küçük pasajı üzerine bu

<?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/"> 

gibi bir şey modificate için. Bu şema XSD dağıtımı için hizmet vermektedir. altınızda bu etiketi içine

<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> 

Sonraki biz yöntem adı gösterecek misin

<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> 

olanlar yukarıdaki etiketi devam sen service.xsd dosyada ne varsa almak ya http://localhost:8080/webService/servlet-url?xsd=1 bunu göstereceğiz. Sonraki

<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> 

Yukarıdaki katranlar, sizin operasyonunuzu koymak içindir. Devam

<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> 

Sonraki

Ve bir :)

<wsdl:service name="webServiceExample"> 
    <wsdl:port name="webServiceExamplePort" binding="tns:webServiceExamplePortBinding"> 
     <soap:address location="REPLACE_WITH_ACTUAL_URL"/> 
</wsdl:port> 
nihayet bitti :) Eğer etiketi ile geçerli etiketi değiştirmek zorunda

Not<wsdl:...></wsdl:...>

Kaydet, herkese açık ve eğlenceliydin XSD şeması WSDL'da sunulmuştur.

Umarım yardımcı olurum. Çav.

+0

Maalesef çalışmadı. Hala şema xsd, http yoluyla sunulmamaktadır. – bemol

+0

Lütfen, bana nasıl yaptığını göster ve bana WSDL dosyanızı göster. :) – hekomobile