0

我正在构建一个 web 服务,但是当我测试 webservice 时发生错误。并且 wsdl 文件也没有生成。所以如何从 web 服务生成 wsdl 文件?我使用了 netbeans IDE 6.9.1。我的代码如下:

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

}
4

3 回答 3

0

由于您使用的是 Netbeans,因此创建 Web 服务相当简单。

请阅读这篇文章: http: //netbeans.org/kb/docs/websvc/jax-ws.html

按照步骤操作,如果您有疑问,请在此处发布

于 2012-04-09T12:14:56.890 回答
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 服务方法的公共方法添加一个

于 2012-04-09T12:54:14.407 回答
0

您需要添加-J-Djavax.xml.accessExternalSchema=allnetbeans_default_options文件 /etc/netbeans.conf 中。

在此更改之后,您的 netbeans 将能够使用您的 Web 服务解析 WSDL 文件。

于 2017-06-11T23:58:23.413 回答