简体   繁体   English

WebService:wsdl 文件未生成

[英]WebService:wsdl file is not generated

I am build a webservice but error is occurred to when i am test webservice.and wsdl file also not generated.so how to generate wsdl file from a webservice?i used.netbeans IDE 6.9.1.my code is given below:我正在构建一个 web 服务,但是当我测试 web 服务时发生错误。并且 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;
  }

}

Since you are using Netbeans, it is fairly simple to create a webservice.由于您使用的是 Netbeans,因此创建 Web 服务相当简单。

Please go through this article: http:/.netbeans.org/kb/docs/websvc/jax-ws.html请go通过这篇文章: http:/.netbeans.org/kb/docs/websvc/jax-ws.html

Follow the steps and if you have doubts, post it here按照步骤操作,如果您有疑问,请在此处发布

You'll have to exclude all public methods which you don't want to be treated as Webservice Methods:您必须排除所有不想被视为 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

Solution: add an @WebMethod(exclude = true) to all public methods you don't want to expose as webservice method解决方案:将@WebMethod(exclude = true)添加到您不想公开为 webservice 方法的所有公共方法

You need to add -J-Djavax.xml.accessExternalSchema=all to netbeans_default_options in file /etc.netbeans.conf.您需要将-J-Djavax.xml.accessExternalSchema=all添加到文件 /etc.netbeans.conf 中的netbeans_default_options

After this change, your.netbeans will be able to parse WSDL file using your webservices.进行此更改后,your.netbeans 将能够使用您的网络服务解析 WSDL 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM