1. 程式人生 > >通過WSDL生成客戶端程式碼

通過WSDL生成客戶端程式碼

目錄

WSDL(Web Service Description Language),描述一個服務。

Axis支援三種方式操作WSDL:

2 提供”WSDL2Java”工具使用WSDL描述來生成Java代理和skeletons

3 提供”Java2WSDL”工具通過JavaClasses生成WSDL

1.WSDL2Java:Building stubs,skeletons,and data types from WSDL

使用org.apache.axis.wsdl.WSDL2Java來生成Java程式碼

% java -cp %AXISCLASSPATH%org.apache.axis.wsdl.WSDL2Java  (WSDL-file-URL)

1.1示例

Java程式碼:

/**
 * 使用者資訊服務介面
 * @author
 *
 */
public interface IUserService {
 
   User queryUser(int id);
  
   void addUser(User user);
  
   List<User> queryList();
  
   String queryUser();
}
 
/**
 * 對外提供查詢使用者資訊服務
 * @author
 *
 */
public class UserService implements IUserService {
 
   @Override
   public User queryUser(int id) {
      return new User(id, "李四 ", 20, "男", "湖南長沙");
   }
 
   @Override
   public void addUser(User user) {
     
   }
 
   @Override
   public List<User> queryList() {
      List<User> userList = newArrayList<User>();
      userList.add(new User(1, "lisi", 23, "男", "南山"));
      userList.add(new User(2, "lisi", 23, "男", "南山"));
      userList.add(new User(3, "lisi", 23, "男", "南山"));
      userList.add(new User(4, "lisi", 23, "男", "南山"));
      userList.add(new User(5, "lisi", 23, "男", "南山"));
      userList.add(new User(6, "lisi", 23, "男", "南山"));
      return userList;
   }
 
   @Override
   public StringqueryUser() {
      return"李四";
   }
  
  
}
 
public class User {
  
   private int id;
   private String name;
   private int age;
   private String sex;
   private String address;
   //get、set方法省略
   public User(int id, String name, int age, String sex, Stringaddress) {
      super();
      this.id = id;
      this.name = name;
      this.age = age;
      this.sex = sex;
      this.address = address;
   }
   public User() {
      super();
   }
  
}

deploy.wsdd:

<!-- Use this fileto deploy some handlers/chains and services     -->
<!-- Two ways to dothis:                                          -->
<!--   java org.apache.axis.client.AdminClientdeploy.wsdd          -->
<!--      after the axis server is running                          -->
<!-- or                                                            -->
<!--   java org.apache.axis.utils.Adminclient|server deploy.wsdd   -->
<!--      from the same directory that the Axis engineruns         -->
 
<deployment name="test"xmlns="http://xml.apache.org/axis/wsdd/"
   xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
 
 
  <service name="userservice"provider="java:RPC">
   
   
    <parameter name="className"value="com.pan.service.impl.UserService"/>
    <parameter name="allowedMethods"value="*"/>
 
   <typeMapping qname="ns:user" xmlns:ns="http://localhost:8080/axis_test/services/userservice/local"
   languageSpecificType="java:com.pan.model.User"
   serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
   deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </service>
 
</deployment>

釋出服務,並儲存userservice.wsdl檔案

生成客戶端程式碼,程式碼結構為:

com

       pan

              model

                     User.java

localhost

       axis_test

              services

                     userservice

                            UserService.java

                            UserServiceService.java

                            UserServiceServiceLocator.java

                            UserserviceSoapBindingStub.java

1.2測試

測試程式碼:

public class ClientTest {
  
   public static void main(String[] args) {
      UserServiceServiceLocator locator = newUserServiceServiceLocator();
      try {
         UserService userService = locator.getuserservice();
         User user = userService.queryUser(1);
         System.out.println(user.getName());
      } catch (ServiceException | RemoteException e) {
         e.printStackTrace();
      }
     
   }
 
}

1.2.1異常:沒有定義com.pan.model.User的序列化的實現

   這個問題的原因是預設情況下Axis只對java對的基本型別進行序列化和反序列化的實現,至於自己定義的類的序列化和反序列化可以自己配置,通過<typeMapping>元素配置,可以配置為Axis中已實現的序列化和反序列化類

<typeMapping qname="ns:user" xmlns:ns="http://localhost:8080/axis_test/services/userservice/local"
   languageSpecificType="java:com.pan.model.User"
   serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
   deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
   encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>


1.3WSDL與生成的客戶端程式碼結構分析

WSDL clause

Java class(es) generated

For each entry in the type section

A java class

For each portType

A java interface

For each binding

A stub class

For each service

A service interface

A service implementation (the locator)

通過WSDL中type來生成Java類,通常這個類是一個Java Bean。例

<complexType name="user">
<sequence>
<element name="address" nillable="true" type="xsd:string"/>
<element name="age" type="xsd:int"/>
<element name="id" type="xsd:int"/>
<element name="name" nillable="true" type="xsd:string"/>
<element name="sex" nillable="true" type="xsd:string"/>
</sequence>
</complexType>


生成的Java程式碼為:

/**
 *User.java
 *
 *This file was auto-generated from WSDL
 * bythe Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
 */
 
package com.pan.model;
 
public class User  implements java.io.Serializable {
   private java.lang.String address;
 
   private int age;
 
   private int id;
 
   private java.lang.String name;
 
   private java.lang.String sex;
 
   public User() {
    }
 
   public User(
          java.lang.String address,
          int age,
          int id,
          java.lang.String name,
          java.lang.String sex) {
          this.address = address;
          this.age = age;
          this.id = id;
          this.name = name;
          this.sex = sex;
    }
 
 
   /**
    * Gets the address value for this User.
    *
    * @return address
    */
   public java.lang.String getAddress() {
       return address;
    }
 
 
   /**
    * Sets the address value for this User.
    *
    * @param address
    */
   public void setAddress(java.lang.String address) {
       this.address = address;
    }
 
 
   /**
    * Gets the age value for this User.
    *
    * @return age
    */
   public int getAge() {
       return age;
    }
 
 
   /**
    * Sets the age value for this User.
    *
    * @param age
    */
   public void setAge(int age) {
       this.age = age;
    }
 
 
   /**
    * Gets the id value for this User.
    *
    * @return id
    */
   public int getId() {
       return id;
    }
 
 
   /**
    * Sets the id value for this User.
    *
    * @param id
    */
   public void setId(int id) {
       this.id = id;
    }
 
 
   /**
     * Gets the name value for this User.
    *
    * @return name
    */
   public java.lang.String getName() {
       return name;
    }
 
 
   /**
    * Sets the name value for this User.
    *
    * @param name
    */
   public void setName(java.lang.String name) {
       this.name = name;
    }
 
 
   /**
    * Gets the sex value for this User.
    *
    * @return sex
    */
   public java.lang.String getSex() {
       return sex;
    }
 
 
   /**
    * Sets the sex value for this User.
     *
    * @param sex
    */
   public void setSex(java.lang.String sex) {
       this.sex = sex;
    }
 
   private java.lang.Object __equalsCalc = null;
   public synchronized boolean equals(java.lang.Object obj) {
       if (!(obj instanceof User)) return false;
       User other = (User) obj;
       if (obj == null) return false;
       if (this == obj) return true;
       if (__equalsCalc != null) {
           return (__equalsCalc == obj);
       }
       __equalsCalc = obj;
       boolean _equals;
       _equals = true &&
           ((this.address==null && other.getAddress()==null) ||
            (this.address!=null &&
             this.address.equals(other.getAddress()))) &&
           this.age == other.getAge() &&
           this.id == other.getId() &&
           ((this.name==null && other.getName()==null) ||
            (this.name!=null &&
             this.name.equals(other.getName()))) &&
           ((this.sex==null && other.getSex()==null) ||
            (this.sex!=null &&
             this.sex.equals(other.getSex())));
       __equalsCalc = null;
       return _equals;
    }
 
   private boolean __hashCodeCalc = false;
   public synchronized int hashCode() {
       if (__hashCodeCalc) {
           return 0;
        }
       __hashCodeCalc = true;
       int _hashCode = 1;
       if (getAddress() != null) {
           _hashCode += getAddress().hashCode();
       }
       _hashCode += getAge();
       _hashCode += getId();
       if (getName() != null) {
            _hashCode += getName().hashCode();
       }
       if (getSex() != null) {
           _hashCode += getSex().hashCode();
       }
       __hashCodeCalc = false;
       return _hashCode;
    }
 
   // Type metadata
   private static org.apache.axis.description.TypeDesc typeDesc =
       new org.apache.axis.description.TypeDesc(User.class, true);
 
   static {
       typeDesc.setXmlType(newjavax.xml.namespace.QName("http://model.pan.com", "User"));
       org.apache.axis.description.ElementDesc elemField = neworg.apache.axis.description.ElementDesc();
       elemField.setFieldName("address");
       elemField.setXmlName(new javax.xml.namespace.QName("","address"));
       elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema","string"));
       elemField.setNillable(true);
       typeDesc.addFieldDesc(elemField);
       elemField = new org.apache.axis.description.ElementDesc();
       elemField.setFieldName("age");
       elemField.setXmlName(new javax.xml.namespace.QName("","age"));
       elemField.setXmlType(newjavax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema","int"));
       elemField.setNillable(false);
       typeDesc.addFieldDesc(elemField);
       elemField = new org.apache.axis.description.ElementDesc();
       elemField.setFieldName("id");
       elemField.setXmlName(new javax.xml.namespace.QName("","id"));
       elemField.setXmlType(newjavax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema","int"));
       elemField.setNillable(false);
       typeDesc.addFieldDesc(elemField);
       elemField = new org.apache.axis.description.ElementDesc();
       elemField.setFieldName("name");
       elemField.setXmlName(new javax.xml.namespace.QName("","name"));
       elemField.setXmlType(newjavax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema","string"));
       elemField.setNillable(true);
       typeDesc.addFieldDesc(elemField);
       elemField = new org.apache.axis.description.ElementDesc();
       elemField.setFieldName("sex");
       elemField.setXmlName(new javax.xml.namespace.QName("","sex"));
       elemField.setXmlType(newjavax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema","string"));
       elemField.setNillable(true);
        typeDesc.addFieldDesc(elemField);
    }
 
   /**
    * Return type metadata object
    */
   public static org.apache.axis.description.TypeDesc getTypeDesc() {
       return typeDesc;
    }
 
   /**
    * Get Custom Serializer
    */
   public static org.apache.axis.encoding.Serializer getSerializer(
          java.lang.String mechType,
          java.lang.Class _javaType, 
          javax.xml.namespace.QName _xmlType) {
       return
         new org.apache.axis.encoding.ser.BeanSerializer(
           _javaType, _xmlType, typeDesc);
    }
 
   /**
    * Get Custom Deserializer
    */
   public static org.apache.axis.encoding.Deserializer getDeserializer(
          java.lang.String mechType,
          java.lang.Class _javaType,  
          javax.xml.namespace.QName _xmlType) {
       return
         new org.apache.axis.encoding.ser.BeanDeserializer(
           _javaType, _xmlType, typeDesc);
    }
 
}


這種型別可作為輸入輸出引數,Java沒有輸入/出引數的概念,為了實現這種行為,定義了holder類,這個holder類簡單的包括原有類的一個例項。

package samples.addr.holders;
 
public final class PhoneHolder implementsjavax.xml.rpc.holders.Holder {
  publicsamples.addr.Phone value;
 
  publicPhoneHolder() {
  }
 
  publicPhoneHolder(samples.addr.Phone value) {
    this.value =value;
  }
}


A holder class is only generated for a type if that type isused as an inout or out parameter. Note that the holder class has the suffix"Holder" appended to the class name, and it is generated in asub-package with the "holders".

The holder classesfor the primitive types can be found in javax.xml.rpc.holders.

Service Definition Interface(SDI)來自WSDL的portType,這個介面允許你去訪問服務的方法。WSDL示例:

<message name="empty">
<message name="AddEntryRequest">
  <partname="name" type="xsd:string"/>
  <partname="address" type="typens:address"/>
</message>
<portType name="AddressBook">
  <operationname="addEntry">
    <inputmessage="tns:AddEntryRequest"/>
    <outputmessage="tns:empty"/>
 </operation>
</portType>


生成的SDI:

public interface AddressBook extends java.rmi.Remote {
  public voidaddEntry(String name, Address address) throws
     java.rmi.RemoteException;
}

SDI的名字通常是通過portType的name來確定,但是構造SDI,需要從portType binding瞭解更多的資訊.

JAX-RPC中說道:java介面的名字從wsdl:portType元素的name屬性對映而來,如果使用wsdl:binding元素對映SDI,那麼SDI的名字從wsdl:binding元素的name屬性對映而來。

一個實現SDI的Stub類,類的名字為binding的name值+字尾”Stub”,它包含使用Axis Service和Call物件來進行方法的呼叫,它是一個遠端服務的代理,以至於你可以把它當作本地物件來處理。另一方面,你不需要去處理endpont URL,namespace,或引數陣列動態呼叫的問題,這個Stub隱藏了所有的工作併為你服務。

示例:

WSDL片段:

<binding name="AddressBookSOAPBinding"type="tns:AddressBook">
  ...
</binding>


生成的Stub類(片段):

public class AddressBookSOAPBindingStub extendsorg.apache.axis.client.Stub
    implementsAddressBook {
  publicAddressBookSOAPBindingStub() throws org.apache.axis.AxisFault {...}
 
  publicAddressBookSOAPBindingStub(URL endpointURL,
     javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {...}
 
  publicAddressBookSOAPBindingStub(javax.xml.rpc.Service service)
      throwsorg.apache.axis.AxisFault {...}
 
  public voidaddEntry(String name, Address address)
      throwsRemoteException {...}
}


通常,客戶端程式不會直接示例化Stub,或示例化一個service locator並呼叫get方法返回一個Stub.這個locator通過WSDL中的service來生成,WSDL2Java通過service元素會生成兩個物件,示例:

WSDL:

<service name="AddressBookService">
  <portname="AddressBook" binding="tns:AddressBookSOAPBinding">
   <soap:address location="http://localhost:8080/axis/services/AddressBook"/>
  </port>
</service>


WSDL2Java生成服務介面:

public interface AddressBookService extendsjavax.xml.rpc.Service {
  public StringgetAddressBookAddress();
 
  publicAddressBook getAddressBook() throws javax.xml.rpc.ServiceException;
 
  publicAddressBook getAddressBook(URL portAddress)
      throwsjavax.xml.rpc.ServiceException;
}


同時,生成locator來實現這個介面:

public class AddressBookServiceLocator extendsorg.apache.axis.client.Service
    implementsAddressBookService {
  ...
}


這個服務介面定義一個get方法獲取每個在WSDL中定義的port ,locator實現這個服務介面,實現這些get方法。它可以獲取Stub的例項。Service類會預設建立一個Stub,當你請求PortType的時候可能需要指定一個不同的URL。

下面給出一個典型的使用Stub類的示例:

public class Tester {
  public staticvoid main(String [] args) throws Exception {
    // Make aservice
   AddressBookService service = new AddressBookServiceLocator();
 
    // Now use theservice to get a stub which implements the SDI.
    AddressBookport = service.getAddressBook();
 
    // Make theactual call
    Address address= new Address(...);
   port.addEntry("Russell Butek", address);
  }
}


Stub是Web Service在客戶端的Java表示,一個skeleton是一個服務端的Java框架,為了生成skeleton類,你只需要指定在使用WSDL2Java的時候指定選項:” --server-side --skeletonDeploy true”,例:

% java -cp %AXISCLASSPATH%org.apache.axis.wsdl.WSDL2Java --server-side --skeletonDeploy trueWSDL-file-URL

會生成之前客戶端所有的類,同時會生成一些新的檔案:

WSDL clause

Java class(es) generated

For each binding

A skeleton class

An implementation template class

For all services

One deploy.wsdd file

One undeploy.wsdd file

如果你沒有指定”—skeletonDeploy true”選項,skeleton將不會生成,deploy.wsdd中將直接通過實現類來進行釋出。在這種情況下,deploy.wsdd包含描述實現類操作和引數的元資料,這種情況生成的檔案如下;

WSDL clause

Java class(es) generated

For each binding

An implementation template class

For all services

One deploy.wsdd file with operation meta data

One undeploy.wsdd file

       這裡我做了一個測試:就是想通過deploy.wsdd進行部署,但始終沒有成功,後來發現,原來我一直都是在客戶端專案中進行部署,這樣是不會識別到相應的class的,所以一直出現ClassNotFoundException異常,必須將相應的java程式碼拷貝到服務端的專案中,然後再部署即可。通過這個測試可以瞭解到:之所以能將寫好的class釋出成Web Service依賴於當前所支援釋出的環境及操作。我這裡使用的是AdminClient進行釋出,物件是相應的web應用,所以需要在WEB應用的支援下才能釋出成Web Service。

上述釋出和生成客戶端程式碼及再次部署的過程類似於下圖所示:

 

       上述過程可以看出,通過WSDL可以解耦客戶端和服務端,首先編寫好相應的WSDL,客戶端通過WSDL生成呼叫程式碼,服務端通過WSDL生成模板服務程式碼和部署/解暑檔案。同時客戶端也可以生成模板服務程式碼,然後自己去寫一些測試資料,通過呼叫測試資料來開展自己的工作,當服務端開發完後,只需要部署成Web Service即可,客戶端再將相應呼叫程式碼修改為生成的客戶端呼叫程式碼即可。更好的處理方法是:服務端對服務方法寫一個mock,即填寫模擬資料返回,然後釋出服務,客戶端呼叫這些服務,當服務端實現服務後,客戶端可以不用做任何修改。

 


1.3.6.1 Skeleton Description(for Skeleton Deployment)

Skeleton類介於Axis引擎和服務實現類之間,它的名字為binding的name+字尾”Skeleton”,對於AddressBook binding,WSDL2Java生成如下:

public class AddressBookSOAPBindingSkeleton implementsAddressBook,
   org.apache.axis.wsdl.Skeleton {
  privateAddressBook impl;
 
  publicAddressBookSOAPBindingSkeleton() {
    this.impl = newAddressBookSOAPBindingImpl();
  }
 
  publicAddressBookSOAPBindingSkeleton(AddressBook impl) {
    this.impl =impl;
  }
 
  public voidaddEntry(java.lang.String name, Address address)
      throwsjava.rmi.RemoteException {
   impl.addEntry(name, address);
  }
}


真正的skeleton的內容比上面的更豐富,這裡只是基本的資訊。

Skeleton包含一個實現類

實現類模板描述

WSDL2Java生成的實現模板類如下:

public class AddressBookSOAPBindingImpl implementsAddressBook {
  public voidaddEntry(String name, Address address)
      throwsjava.rmi.RemoteException {
  }
}


這個模板通常被用來建立一個測試實現,它裡面沒有做任何事情。

WSDL2Java生成模板類的時候,當模板類不存在,則生成,當模板類存在,則不覆蓋。

Java2WSDL工具通過java程式碼來生成WSDL,如果你對WSDL不太熟悉,你可以通過這種方式來生成WSDL

2.1步驟

2.1.1提供一個Java介面或類

編寫和編譯一個java介面(或類)來描述服務介面。例:

package samples.userguide.example6;
 
/**
 * Interfacedescribing a web service to set and get Widget prices.
 **/
public interface WidgetPrice {
  public voidsetWidgetPrice(String widgetName, String price);
  public StringgetWidgetPrice(String widgetName);
}


2.1.2使用Java2WSDL建立WSDL

例:

% java –cp %AXISCLASSPATH% org.apache.axis.wsdl.Java2WSDL-o wp.wsdl

   -l"http://localhost:8080/axis/services/WidgetPrice"

    -n  "urn:Example6"-p"samples.userguide.example6" "urn:Example6"

   samples.userguide.example6.WidgetPrice

·        -o indicates the name of the output WSDL file

·        -l indicates the location of the service

·        -n is the target namespace of theWSDL file

·        -p indicates a mapping from the package to anamespace. There may be multiple mappings.

·        the class specified contains the interface of thewebservice.

使用WSDL2Java建立繫結

% java –cp %AXISCLASSPATH% org.apache.axis.wsdl.WSDL2Java-o . -d Session -s -S true

    -Nurn:Example6samples.userguide.example6 wp.wsdl

將會生成以下檔案:

·        WidgetPriceSoapBindingImpl.java: Java file containing the default server implementation of theWidgetPrice web service.
You will need to modify the *SoapBindingImpl file to add your implementation

·        WidgetPrice.java:New interface file that contains the appropriate java.rmi.Remoteusages.

·        WidgetPriceService.java:Java file containing the client side service interface.

·        WidgetPriceServiceLocator.java: Java file containing the client side service implementationclass.

·        WidgetPriceSoapBindingSkeleton.java: Server side skeleton.

·        WidgetPriceSoapBindingStub.java: Client side stub.

·        deploy.wsdd:Deployment descriptor

·        undeploy.wsdd:Undeployment descriptor

·        (data types): Java fileswill be produced for all of the other types and holders necessary for the webservice. There are no additional files for the WidgetPrice web service.

相關推薦

通過WSDL生成客戶程式碼

目錄 WSDL(Web Service Description Language),描述一個服務。 Axis支援三種方式操作WSDL: 2 提供”WSDL2Java”工具使用WSDL描述來生成Java代理和skeletons 3 提供”

spring boot 整合webservice axis(2) axis由wsdl或者xml生成客戶程式碼

1.點選專案右鍵新增other如下圖 2.選擇 3.選擇wsdl檔案 4.選擇程式碼生成的位置 5.在pom.xml中引入axis依賴或者在普通專案中引入jar包 spring boot 整合webservice axis(1) eclipse axis外掛安裝 sp

wsdl介面,用cmd生成客戶程式碼

wsimport -s D:\cos\pa -p com.sf.customer.service.core.web.ws.client.cos.paramTypeService -keep http://127.0.0.1:8080/cos_webservice/servi

WebService學習總結 三 利用本地wsdl文件生成客戶程式碼和TCP/IP工具監聽請求

一 利用本地文件生成客戶端程式碼: 之前都是利用網路上的wsdl文件生成客戶端程式碼,現狀可以先訪問網路上的wsdl文件,再把文件儲存到本地,使用 wsimport -keep 本地wsdl文件路徑,來生成客戶端程式碼。 例如 wsimport -keep D:\java\

使用cmd webservice wsdl網址生成客戶程式碼

1.必須安裝jdk環境 2.開啟cmd 3. 嘗試使用wsimport命令 命令引數說明: -d:生成客戶端執行類的class檔案的存放目錄(預設存放在C:\Users\Administrator\)包含.java和.class檔案 -s:生成客戶端執行類的原始檔的存放目

使用CXF將wsdl檔案生成客戶程式碼命令

1、先下載cxf包 http://cxf.apache.org/download.html,現在cxf包。(下載資源就有)2、解壓縮包,通過cmd命令進入到bin目錄下(cd cxf\bin的路徑) cxf生成客戶端程式碼 3、使用wsdl2java命令生成客戶端程式碼

WSDL控制檯中wsimport命令生成客戶程式碼報錯解決方案

在使用webservice時,利用jdk自帶的wsimport.exe生成客戶端程式碼時發生如下錯誤: 正在解析 WSDL... [ERROR] Unexpected end of file from server 無法讀取 WSDL 文件: http://localhos

使用java的wsimport.exe工具生成wsdl客戶程式碼

在jdk的bin目錄下有一個wsimport.exe的工具,使用該工具可以根據wsdl地址生成java的客戶端程式碼。 常用命令如下: wsimport -keep -d d:\ -s d:\src -p com.map -verbose http://192.168.

CXF生成客戶程式碼並打包成jar檔案

最近其他部門提供了WebService介面,本地開發使用的是Java,現在選擇使用根據WSDL文件打成Jar包的方式來處理,在此記錄一下命令 CXF工具請百度自行安裝 CXF生成客戶端程式碼並打包成jar檔案: wsdl2java -frontend jaxws21 -encoding ut

使用Swagger的Json文件生成客戶程式碼

一. 線上工具方式 線上訪問 Swagger Editor 編寫 Swagger 文件 線上生成程式碼 二. 命令建立(需有java環境) 編寫 Swagger Json文件 下載打包工具 swagger-codegen-cli

webservice 生成客戶程式碼

命令如下: wsimport -keep -d d:\ -s d:\src -p com.hello -verbose http://127.0.0.1:9999/hello?wsdl -d:指定class檔案的存放目錄 -s:指定原始碼java輸出目錄  -p:以pac

用eclipse呼叫遠端webservice生成客戶程式碼

以前在呼叫webservice的時候都是自己老老實實用axis寫程式碼,今天在網上看到在myeclipse裡面可以根據wsdl介面地址自動生成介面呼叫客戶端程式碼,於是我就想到在eclipse裡面是不是也可以根據wsdl介面地址自動生成介面客戶端呼叫程式碼呢?答案是肯定的,

怎樣使用cxf webservice並生成客戶程式碼

1.首先編寫webservice介面2.編寫webservice實現類3.在web.xml中配置cxf攔截器4.與spring整合(在spring-context.xml)中新增配置項5.在瀏覽器中使用wsdl生成xml檔案,如果正常生成則配置成功,在瀏覽器中應輸入http:

cxf釋出webservice簡介 及 wsdl2java生成客戶程式碼

下面我們簡要介紹如何通過cxf框架釋出webservice 首先新建一個Java project為cxfmodel_server 首先去官網下載cxf:http://cxf.apache.org/download.html 下面我們就開始使用 (1)釋出服務 第一步:新建

cxf在cmd中通過wsdl2java生成客戶檔案

E:\apache-cxf-3.1.0\bin>wsdl2java -p com.service.cxf -d e:\workspaces\testproject\src -verbose "E:\loginService.xml"

eclipse 根據 wsdl 生成服務程式碼

一般的webservice 都是我們做好了服務端,生成wsdl給別人來用,特別是jdk 1.6 之後,jdk原生支援 webservice,開發介面更是簡單了許多。 不過公司新專案卻需要根據 wsdl 來生成服務端,沒辦法,對方是大公司,我們只能迎合對方的要求

JDK釋出webservice服務,並生成客戶程式碼實戰

一 jdk釋出webservice服務 第一步:新建一個工程ws_jdk_server 新建類HelloServer.java package com.ws.server; import java

webservcie生成客戶程式碼報錯----javax.xml.ws.soap.SOAPFaultException: Cannot create a secure XMLInputFactory

javax.xml.ws.soap.SOAPFaultException: Cannot create a secure XMLInputFactory 這個問題困擾了我一天,媽的,後來才發現是缺少了兩個jar包,如下: 伺服器端缺少了兩個jar包  stax2-api-3

cxf的wsdl2java工具生成客戶程式碼

 wsdl2java用法: wsdl2java -p com -d src -all  aa.wsdl -p  指定其wsdl的名稱空間,也就是要生成程式碼的包名: -d  指定要產生程式碼所在目錄 -client 生成客戶端測試web service的程式碼 -server 生成伺服器啟動web  serv

webservice wsdl2Java 生成客戶程式碼

1  環境配置 將CXF_HOME/bin加入到環境變數path中,如我的是D:\Java\Jar\apache-cxf-2.7.7\bin 開啟cmd輸入 wsdl2java -v 出現如下資訊表示配置成功 2、wsdl2java的使用 (1)建立一個"Jav