2012-04-09 349 views
0

我構建了一個web服務,但是當我測試webservice.and wsdl文件時也沒有生成錯誤,因此如何從webservice生成wsdl文件?我使用netbeans IDE 6.9.1 .my代碼如下:WebService:不生成wsdl文件

@WebService(targetNamespace = "http://my.org/ns/") 
public class vendor1 implements Serializable { 

    static String licenseType = "Subscription"; 
    String re = "successfully"; 

    @WebMethod(operationName = "licence") 
    public String licence(@WebParam(name = "fullName") String fullName, @WebParam(name = "company") String company, @WebParam(name = "emailID") String emailID, @WebParam(name = "phone") String phone, @WebParam(name = "address") String address, @WebParam(name = "city") String city, @WebParam(name = "state") String state, @WebParam(name = "country") String country, @WebParam(name = "zipcode") String zipcode, @WebParam(name = "productID") String productID, @WebParam(name = "activationPeriod") int levelID, @WebParam(name = "levelID") int activationPeriod, @WebParam(name = "password") String password) throws Exception { 
    Connection con = connectToDb(); 
    re = insertIntoCustomerTlb(con, fullName, company, emailID, phone, address, city, state, country, zipcode, productID, levelID); 
    re= insertIntoLicenseKeyTlb(con, emailID, licenseType, fullName, productID, activationPeriod); 
    re=insertIntoNoOfLicensesTlb(con, emailID); 
    con.close(); 

    //String re="successfully"; 
    return re; 
    } 

    public Connection connectToDb() throws ClassNotFoundException, SQLException { 
    Connection con = null; 
    // String re = null; 
    String url = "jdbc:mysql://localhost:3306/"; 
    String db = "plm"; 
    String driver = "com.mysql.jdbc.Driver"; 
    Class.forName(driver); 
    con = DriverManager.getConnection(url + db, "root", "root"); 
    return con; 
    } 

    public String insertIntoCustomerTlb(Connection con, String fullName, String company, String email, String phone, String address, String city, String state, String contry, String zipCode, String productID, int levelID) { 
    if (company == null) { 
     company = " "; 
    } 
    /*if(address==null) 
    { 
    address=" "; 
    } 
    if(city==null) 
    { 
    city=" "; 
    } 
    if(state==null) 
    { 
    state=" "; 
    } 
    String re=null;*/ 

    /*Connection con = null; 

    String url = "jdbc:mysql://localhost:3306/"; 
    String db = "jdbctutorial"; 
    String driver = "com.mysql.jdbc.Driver";*/ 
    String CustomerInfoQuery = "insert into `tlb_customer_master`(`Full_Name`,`Company`,`Email`,`Phone`,`Address`,`City`,`State`,`Country`,`Zip_Code`,`Product_ID`,`Level_ID`) values (?,?,?,?,?,?,?,?,?,?,?)"; 
    //try{ 
    // Class.forName(driver); 
    //con = DriverManager.getConnection(url+db,"root","root"); 
    try { 
     //Statement st = con.createStatement(); 
     //int rowsAffected =st.executeUpdate("); 
     // System.out.println("1 row affected"); 
     PreparedStatement ps = con.prepareStatement(CustomerInfoQuery); 
     ps.setString(1, fullName); 
     ps.setString(2, company); 
     ps.setString(3, email); 
     ps.setString(4, phone); 
     ps.setString(5, address); 
     ps.setString(6, city); 
     ps.setString(7, state); 
     ps.setString(8, contry); 
     ps.setString(9, zipCode); 
     ps.setString(10, productID); 
     ps.setInt(11, levelID); 
     ps.execute(CustomerInfoQuery); 
     ps.close(); 
    } catch (SQLException s) { 
     re = "error"; 
    } 
    return re; 
} 

public String insertIntoCustomerValidationTlb(Connection con, String email, String password) { 
    String CustomerInfoQuery = "insert into `tlb_customer_validation_master`(`Email`,`Password`) values (?,?)"; 
    try { 

     PreparedStatement ps = con.prepareStatement(CustomerInfoQuery); 

     ps.setString(1, email); 
     ps.setString(2, password); 

     ps.execute(CustomerInfoQuery); 
     ps.close(); 
    } catch (SQLException s) { 
     re = "error"; 
    } 


    return re; 

} 

public String insertIntoLicenseKeyTlb(Connection con, String emailID, String licenseType, String fullName, String productID, int activationPeriod) { 

    try { 
     Statement st = con.createStatement(); 
     if (activationPeriod == 1) { 
      String queryLicenseKey1 = "insert into `tlb_license_key_master`(`Email`,`License_Type`,`Full_Name`,`Product_ID`,`Activation_Date`,`Expiry_Date`) VALUES('" + emailID + "','" + licenseType + "','" + fullName + "','" + productID + "',now(),DATE_ADD(now(), INTERVAL 1 MONTH))"; 
      // String queryLicenseKey2 ="insert into tlb_license_key_master (Major_Version,Minor_Version) values(select Major_Version,Minor_Version from tlb_product_master where Product_ID="+productID+")"; 
      int rowsAffected1 = st.executeUpdate(queryLicenseKey1); 
     } 
     if (activationPeriod == 6) { 
      String queryLicenseKey1 = "insert into `tlb_license_key_master`(`Email`,`License_Type`,`Full_Name`,`Product_ID`,`Activation_Date`,`Expiry_Date`) VALUES('" + emailID + "','" + licenseType + "','" + fullName + "','" + productID + "',now(),DATE_ADD(now(), INTERVAL 6 MONTH))"; 
      // String queryLicenseKey2 ="insert into tlb_license_key_master (Major_Version,Minor_Version) values(select Major_Version,Minor_Version from tlb_product_master where Product_ID="+productID+")"; 
      int rowsAffected1 = st.executeUpdate(queryLicenseKey1); 
     } 
     if (activationPeriod == 12) { 
      String queryLicenseKey1 = "insert into `tlb_license_key_master`(`Email`,`License_Type`,`Full_Name`,`Product_ID`,`Activation_Date`,`Expiry_Date`) VALUES('" + emailID + "','" + licenseType + "','" + fullName + "','" + productID + "',now(),DATE_ADD(now(), INTERVAL 12 MONTH))"; 
      // String queryLicenseKey2 ="insert into tlb_license_key_master (Major_Version,Minor_Version) values(select Major_Version,Minor_Version from tlb_product_master where Product_ID="+productID+")"; 
      int rowsAffected1 = st.executeUpdate(queryLicenseKey1); 
     } 


     //int rowsAffected2 =st.executeUpdate(queryLicenseKey2); 
     st.close(); 
    } catch (SQLException ex) { 
     re = "error"; 
    } 
    return re; 
} 

public String insertIntoNoOfLicensesTlb(Connection con, String emailID) { 

    try { 
     String queryNoOfLicenses1 = "select * from tlb_no_of_licenses where Email= '" + emailID + "'"; 

     Statement st = con.createStatement(); 
     ResultSet rs = st.executeQuery(queryNoOfLicenses1); 

     int count = 0; 
     while (rs.next()) { 
      count++; 
     } 
     if (count == 0) { 
      String queryNoOfLicenses2 = "insert into `tlb_no_of_licenses` values('" + emailID + "',1,1,0)"; 
      int rowsAffected2 = st.executeUpdate(queryNoOfLicenses2); 
     } else { 
      String queryNoOfLicenses2 = "UPDATE `tlb_no_of_licenses` SET No_Of_Licenses=No_Of_Licenses+1,Active_Licenses=Active_Licenses+1,Disabled_Licenses=No_Of_Licenses-Active_Licenses"; 
      int rowsAffected2 = st.executeUpdate(queryNoOfLicenses2); 

     } 
     rs.close(); 
     st.close(); 
    } catch (SQLException ex) { 
     re = "error"; 
    } 
    return re; 
} 

    public String insertBillingTlb(Connection con, String email) { 
    String CustomerInfoQuery = "insert into `tlb_customer_validation_master`(`Email`,`Bill_Paid`) values (?,?)"; 
    try { 
     PreparedStatement ps = con.prepareStatement(CustomerInfoQuery); 

     ps.setString(1, email); 
     ps.setString(2, "N"); 

     ps.execute(CustomerInfoQuery); 
     ps.close(); 
    } catch (SQLException s) { 
     re = "error"; 
    } 
    return re; 
    } 

} 
+0

你可以發佈你的異常? – maks 2012-04-09 12:25:05

回答

0

由於您使用的是Netbeans,因此創建Web服務相當簡單。

請通過這篇文章:http://netbeans.org/kb/docs/websvc/jax-ws.html

按照以下步驟,如果你有疑問,它張貼在這裏

+0

我在上週創建了一個webservice,並且成功地使用了這些文章和它的運行,但是我在這些webservice中遵循了相同的步驟,但發生錯誤。請參閱代碼並幫助我。 – tapanmodh 2012-04-09 12:18:03

+0

你爲什麼不告訴我們你遇到的錯誤? – stefanglase 2012-04-09 12:29:40

0

你必須排除那些你不希望被當作所有公共方法Web服務方法:

Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions 
java.sql.Connection is an interface, and JAXB can't handle interfaces. 
    this problem is related to the following location: 
     at java.sql.Connection 
     at private java.sql.Connection jaxws.InsertIntoCustomerTlb.arg0 
     at jaxws.InsertIntoCustomerTlb 
java.sql.Connection does not have a no-arg default constructor. 
    this problem is related to the following location: 
     at java.sql.Connection 
     at private java.sql.Connection jaxws.InsertIntoCustomerTlb.arg0 
     at jaxws.InsertIntoCustomerTlb 
java.lang.StackTraceElement does not have a no-arg default constructor. 
    this problem is related to the following location: 
     at java.lang.StackTraceElement 
     at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace() 
     at java.lang.Throwable 
     at private java.lang.Throwable jaxws.ClassNotFoundExceptionBean.exception 
     at jaxws.ClassNotFoundExceptionBean 

解決方法:添加一個@WebMethod(exclude = true)所有的公共方法,你不希望暴露作爲Web服務方法

0

您需要在文件/etc/netbeans.conf中將-J-Djavax.xml.accessExternalSchema=all添加到netbeans_default_options

更改完成後,您的netbeans將能夠使用您的web服務來解析WSDL文件。