RowAtPoint and columnAtPoint always return 0

//in NormalGUI
     ptsinfo.addActionListener(new NTListener());
     delete.addActionListener(new NTListener());
     nTable.addMouseListener(new NTListener());
//in NormalGUI
public class NTListener extends MouseAdapter implements ActionListener{
     int selectRow,selectColumn;
     public void mousePressed(MouseEvent e){
          if (e.isPopupTrigger()) {
               showPopup(e);
     public void mouseReleased(MouseEvent e){
          if (e.isPopupTrigger()) {
               showPopup(e);
     public void showPopup(MouseEvent e){
          NormalGUI.nPop.show(e.getComponent(), e.getX(), e.getY());
          selectRow = NormalGUI.nTable.rowAtPoint(new Point(e.getX(),e.getY()));
          selectColumn = NormalGUI.nTable.columnAtPoint(new Point(e.getX(),e.getY()));
          System.out.println(new Point(e.getX(),e.getY()));     
}the point printed has not problem but rowAtPoint and columnAtPoint.
The popup menu shows at the right point
I try to use e.getSource and find that it really from nTable.
they are always return 0 instead of -1?
Why it happens? Thanks.

Darryl.Burke wrote:
Doesn't happen to me. To get better help sooner, post a SSCCE that clearly demonstrates your problem.
db
import javax.swing.table.*;
import javax.swing.*;
import java.util.*;
class NTable extends AbstractTableModel{
     static Object[] cells = {"",".mpg","大塚愛","ユメクイ",Boolean.FALSE,"2006-08-04","","Mステ","00:02:34","1440x1080","323014660","","","[HDTV] 大塚愛 - [2006.08.04] - ユメクイ ( Mステ - 17Mbps 2m34s 1440x1080).mpg","大塚愛 - ユメクイ (2006.08.04 Mステ) .ts",new Integer(0)};
     static Object[] cells2 = {"",".m2t","大塚愛","金魚花火",Boolean.FALSE,"2004-08-29","BShi","BEAT MOTION","00:02:32","1440x1080","397588604","","","[HDTV-TS] 大塚愛 - [2004.08.29] - 金魚花火 (BShi BEAT MOTION - 20Mbps 2m32s 1440x1080).m2t","大塚愛-金魚花火[BEAT.MOTION.2004.08.29].ts",new Integer(0)};
     int noOfFile;
     static String[] col = {"no.","Suffix","Artist","Songs","Talk","Date","TV station","Program","Duration","Resolution","Filesize","ptsinfo","Date added","new name","old name","rare"};
     static ArrayList<Object[]> datas = new ArrayList<Object[]>();
     public NTable(){
               datas.add(cells);
               datas.add(cells2);
     public int getRowCount(){
          return datas.size();
     public int getColumnCount(){
          return col.length;
    public Object getValueAt(int r, int c){
         if(c==0){
              return String.format("%04d", r+1);
        return getDataList(r)[c];      
     public Class getColumnClass(int c){
          if(c==11){
               try{
                    return JButton.class;
               }catch(Exception e){}
          return getDataList(0)[c].getClass();
     public String getColumnName(int c){
          return col[c];
     public void setValueAt(Object obj, int r, int c){
          Object[] tempArray = getDataList(r);
          tempArray[c] = obj;
          datas.set(r, tempArray);
          if(c==15){
               NormalGUI.nTable.changeSelection(r+1, c, false, false);
     public boolean isCellEditable(int r, int c){
          if(c>0&&c<=10||c==15){
               return true;
          }else{
               return false;
     public static int getdatas(){
          try{
               return datas.size();
          }catch(Exception e){
               return 0;
     public static Object[] getDataList(int r){
          return datas.get(r);
import java.awt.Point;
import java.awt.event.*;
public class NTListener extends MouseAdapter implements ActionListener{
     int selectRow,selectColumn;
     public void mousePressed(MouseEvent e){
        if (e.isPopupTrigger()) {
             showPopup(e);
     public void mouseReleased(MouseEvent e){
        if (e.isPopupTrigger()) {
             showPopup(e);
     public void mouseClicked(MouseEvent e){}     
     public void mouseExited(MouseEvent e){}
     public void mouseEntered(MouseEvent e){}
     public void showPopup(MouseEvent e){
          NormalGUI.nPop.show(e.getComponent(), e.getX(), e.getY());
         selectRow = NormalGUI.nTable.rowAtPoint(new Point(e.getX(),e.getY()));
         selectColumn = NormalGUI.nTable.columnAtPoint(new Point(e.getX(),e.getY()));
         System.out.println(new Point(e.getX(),e.getY()));     
     public void actionPerformed(ActionEvent e){
          if(e.getSource().equals(NormalGUI.ptsinfo)){
                try {
                     Runtime rt = Runtime.getRuntime();               
                     Process prcs = rt.exec("C:\\WINDOWS.0\\AppPatch\\AppLoc.exe \"E:\\(A)&#31243;&#24335; (F)\\&#30475;&#22294;&#25991;&#38899;&#27138;&#39006;\\ptsInfo050\\ptsinfo.exe\" \"/L0411\"");
                     } catch(Exception ioe) { System.out.println(ioe); }
          }else if(e.getSource().equals(NormalGUI.delete)){
               System.out.println(selectRow+"+"+selectColumn);
               NTable.datas.remove(selectRow);
               NormalGUI.nTable.updateUI();
import java.awt.Font;
import javax.swing.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
public class NormalGUI extends JFrame{
     static TableModel nModel;
     static JTable nTable;
     static JScrollPane nPanel;
     static JPopupMenu nPop = new JPopupMenu();
     static JMenuItem ptsinfo = new JMenuItem("Open ptsinfo");
     static JMenuItem delete = new JMenuItem("Delete this file");
     public NormalGUI(){
          setBounds(0,0,500,500);
          nModel = new NTable();
          nTable = new JTable(nModel);   
          nPanel = new JScrollPane(nTable);
          nTable.setRowHeight(20);
          int[] columnWidth={45,145,100,150,45,105,95,200,85,105,115,65,100,900,400,40};
          nTable.setFont(new Font("&#24494;&#36575;&#27491;&#40657;&#39636;", Font.BOLD, 16));
          nTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          nTable.addMouseListener(new NTListener());
          ptsinfo.addActionListener(new NTListener());
          delete.addActionListener(new NTListener());
          nPop.add(ptsinfo);
          nPop.add(delete);
          TableColumn column;
          for (int i = 0; i<nTable.getColumnCount(); i++) {               
               column = nTable.getColumnModel().getColumn(i);
               column.setPreferredWidth(columnWidth);
          add(nPanel);
          setVisible(true);
     public static void main(String[] args){
          new NormalGUI();

Similar Messages

  • HasEventListener and willTrigger always return true

    Hi  everybody.
    I'm trying to achieve the following result.
    I'm listing all items in a form.
    When I encounter a button I check if it has already an event listener applied to it. If not , I apply the event Listener with addEventListener.
    In this way, the next time I'll list the whole form I won't apply the event listener another time (if for example I apply the same event listener twice to a button which insert a new record in a database as result I'll have 2 records added also if the user clicked once...no good at all!!!)
    To accomplish this task I'm using the Actionscript function hasEventListener(EventType) and here comes the weird thing.
    Eveytime I invoke hasEventListener on the form's button it always returns true event if is the first time a list the form (so no event listener applied yet) , even if before to invoke hasEventListener I run removeEventListener.
    I've got the same behavior when i use willTrigger() function, it always returns true no matter when i call it.
    One possible solution could be set a global boolean property to store if Ialready listed the form and applied the event listener to it, but it would be better using hasEventListener, because I've got a class that perform this form listing , and this class is used on wide project, so if I get to fix this problem inside the class I would fix the problem in the entire project in on shot (I love oop programming!!!!)
    Has anybody already addressed this problem?
    Any advisement would be really appreciated.
    Thanks in advance for the attention.
    Best regards!!
    Luke

    Hi, flex harUI.
    Thanks very much for your reply.
    I knew that if I apply an event listener twice it should fire up only once, but this isn't what happen.
    Here's my scenario:
    -  I've got a component with the form inside it
    - Through a menu a go to the state the component is in and I call an "init" function inside the component
    - In the init function I call the Class which activate the form by applying eventlistener on the button
    - The user can navigate away from the component by click another menu item and then return to the component invoking again the form activation (and so let my application apply once again the addEventListener)
    - Here's what happen: the second,third,... time the user return to the component, when he try - for example - to add a record, the record is added two,three... times according to how many times the users "reinitialized" the component. The same things happen when the user tries to delete a record, he is prompted two,three,.... times if he's sure to delete it.....
    It's a really strange behaviour.
    I've found i worked around, by setting a global bool var "initialized" and before call the form activation i check the value of this var, but It's not a very beautiful solution, 'cause I would prefer to fix this problem inside the class, so the fix the problem in the whole project just in one shot!!! (that's why I would like to use hasEventListener() to check if the button has already an eventListener)
    Thaks anyway for the reply!
    If I've some news I'll update ya.
    Bye!

  • Shadowing API Issues on 2012R2 (SM_REMOTECONTROL GetSystemMetrics and WTSStopRemoteControlSession) Always Returns Zero

    According to the MSDN article on the GetSystemsMetric API, SM_REMOTECONTROL returns zero if the user is not currently being shadowed but will return non-zero if the user is currently being shadowed.  It lists no restirction on OS support from what I
    can see.
    WTSStopRemoteControlSession also lists no restrictions on OS support in MSDN.
    I have a simple VB.NET application that calls these APIs.  It basically reads:
    <DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> Public Shared Function GetSystemMetrics(ByVal nIndex as Integer) As Integer
    End Function
    Private Const SM_REMOTECONTROL as Integer = &H2001
    <DllImport("wtsapi32.dll", SetLastError:=True)> Public Shared Function WTSStopRemoteControlSession(ByVal iLoginId as Int32) as Int32
    End Function
    Private Declare Function ProcessIdToSessionId Lib "Kernel32.dll" Alias "ProcessIdToSessionId" (ByVal processID as Int32, ByRef sessionID as Int32) as Boolean
    retVal = GetSystemMetrics(SM_REMOTECONTROL)
    On 2008R2, retVal = 1 when the user is being shadowed, retVal = 0 when the user is not being shadowed.
    On 2012R2, retval = 0 no matter if the user is being shadowed or not shadowed.
    Dim sessionIDCurrent as Int32
    ProcessIdToSessionId(Process.GetCurrentProcess, sessionIDCurrent)
    WTSStopRemoteControlSession(sessionIDCurrent)
    On 2008R2, the shadow session will be stopped and WTSStopRemoteControlSession returns non-zero (indicating success)
    On 2012R2, the sahdow session will NOT be stopped and WTSStopRemoteControlSession returns zero (indicating failure).  LastDLLError returns zero as well.
    Has anyone else run into this?  Is this a known issue?

    Known issue,similar to this question: http://stackoverflow.com/questions/14725781/getsystemmetrics-returns-different-results-for-net-4-5-net-4-0
    http://connect.microsoft.com/VisualStudio/feedback/details/763767/the-systemparameters-windowresizeborderthickness-seems-to-return-incorrect-value
    https://connect.microsoft.com/VisualStudio/feedback/details/753224/regression-getsystemmetrics-delivers-different-values
    Best Regards,
    Please remember to mark the replies as answers if they help

  • What cause Macbook Air A1237 time and date always return from an older date when it restarts? I have tried to reset its PRAM and still it has the same issue.

    So here is the story,
    1. First, this Macbook Air A1237 always display the wrong date and time every time I open it after shutdown.
    2. The Battery always in zero percent and not charging at all.and the magsafe always in color orange.
         *also the battery displays the colored black plug that states it was plug in using the power cord.
    I need help on how to fix this issues.I'm hoping for your kind assistance.
    Grazie Mille!
    Ciao Ciao!
    Regards,
    Freddierick Llarina

    Hi,
    Had similar issue with the same model. It works with power adapter plugged in, but not with battery alone.
    You need to get the battery replaced.
    Cheers,
    Clarence

  • HT201210 I've updated to the latest IOS version. I am now asked to accept the conditions. I click on accept and am always returned to the accept window. What am I missing

    I've updated to the last IOS version and am now asked to accept the conditions. I click on I accept and am constantly referred back to the acceptance window. What am I missing? TIA

    Hi Vulcan37!
    I have some troubleshooting steps for you that can help you resolve this issue. First, you will want to try just performing a reset on your phone by following the instructions in this article:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    You may also need to make sure your Safari settings are set for accepting cookies. More information on this can be found here:
    Privacy and security - iPhone User Guide
    http://help.apple.com/iphone/7/#/iphb01fc3c85
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • Java always returns 15 minutes greater than the current time.

    Hi,
    I am using Microsoft Windows Server 2003R2,Standard X64 edition with Service Pack 2 and jdk1.6.0-03.
    Java always returns time 15 minutes greater than the current system time.
    eg:
    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    System.out.println("Now time: "+simpleDateFormat.format(new Date()));
    System.out.println("Now time: "+new Date());The output of the program is :
    Now time: 2008-12-22 18:47:04
    Now time: Mon Dec 22 18:47:04 NPT 2008
    When my actual system time is 6:32 PM or (18:32)
    I have checked the current time with other programming languages like python and it always returns the actual date and time.
    Note: To my observation java is always utilizing a time which is 15 minutes greater than the current time even for its log.
    Thanks,
    Rajeswari (Msys)

    I think a more practical time machine would be one that actually travels back in time rather than forward (by 15 minutes). Sounds like it needs some more work.
    Anyway, I suggest changing the system time on your computer to some other value (say, 2 hours ahead), then running the program again. If its off by 2 hours and 15 minutes, its getting the time from your computer. However, if its still off by only 15 minutes (from your wristwatch's time), then its getting the time form somehere other than the computer clock.

  • Field Number(19,8) always returns Zero!

    Thanks for reading this
    I am developing an application in VB6 on
    NT 4 SP5 and have come accross a very strange
    error. This project is a migration from
    Sequel Server, I am redoing an ACCESS application.
    In one of the tables, the Latitude and Longitude is stored as of Type Number(19,8)
    (don't ask why - I didn't design the tables).
    All of the data is being retrieved through disconnected ADO recordsets. The data is being written with ADO connection SQL statements.
    Writing of the values through the Oracle ODBC driver seems to work properly (8.01.05 - 02/02/99). When I read the values through a ADO Recordset query, the latitude and longitude always returns 0 (when they are not null).
    I tried switching to the Microsoft ODBC Driver for Oracle, and that driver works fine. The latitude and longitude are correct.
    I can view the data fine through SQL Plus or
    ACCESS via linked Tables, so the data is OK.
    Thanks
    John
    null

    And what does this have to do with JDBC?
    There was a bug in one of the earlier 8.x Oracle ODBC drivers that woukld cause this behavior. Get the latest patch version of the driver frorm Oracle support and you will be fine.

  • Regarding Mail:  When I return to my computer after it has gone to sleep, my accounts go offline, and are always asking me for the password.  THis is very annoying.  How can I prevent this?

    Regarding Mail:  When I return to my computer after it has gone to sleep, my accounts go offline, and are always asking me for the password.  THis is very annoying.  How can I prevent this?

    Back up all data.
    Launch the Keychain Access application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Keychain Access in the icon grid.
    Select the login keychain from the list on the left side of the Keychain Access window. If your default keychain has a different name, select that.
    If the lock icon in the top left corner of the window shows that the keychain is locked, click to unlock it. You'll be prompted for the keychain password, which is the same as your login password, unless you've changed it.
    Right-click or control-click the login entry in the list. From the menu that pops up, select Change Settings for Keychain "login". In the sheet that opens, uncheck both boxes, if not already unchecked.
    From the menu bar, select
    Keychain Access ▹ Preferences ▹ First Aid
    If the box marked Keep login keychain unlocked is not checked, check it.
    Select
    Keychain Access ▹ Keychain First Aid
    from the menu bar and repair the keychain. Quit Keychain Access.

  • My iphone 4 is stuck on the hello screen...with a white background after i tried to update it.  How do i correct this?  I have already gone to itunes and backed it up.  But after i back it up it always return to the hello screen in  different languages ?

    My iphone 4 is stuck in the setup phase with a white background.  It tells me hello in several diffrent  languages and tells me to slide to set up.  I have already backed it up on itunes several times but it always returns to the hello screen with the white back ground.  Can anyone please help me with this?  All of this happened after i updated it for the 1st time. Help pLease?
    Edward

    Hello Edward
    Follow the prompts on your iPhone and you will get either at your home screen like normal or get to a point of restoring from back up. The article below will give step by step for restoring from back up.
    iOS: How to back up and restore your content
    http://support.apple.com/kb/HT1766
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • HT1600 Since the latest up-date I can't see any movies.  I always returns to the main menu.  Is anyone else having this problem and how do I fix it?

    Since the latest up-date I can't see any movies.  It always returns to the main menu.  Is anyone else having this problem and how do I fix it?  We have gone 3 days without the use of renting movies.

    Welcome to the Apple Community.
    First you should try logging out of your iTunes Store account (settings > iTunes Store > accounts) and then back in again.
    If that doesn't help, try resetting the Apple TV (Settings > General > Reset > Reset all settings). You should also try restarting your router.
    If both of the above don't help, you should try a restore (Settings > General > Reset > Restore).

  • Request.getParameter() always returns null

    I have a html file and am trying to retrieve the values from a formin my servlet.
    here is the html code:
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <h1><b>Add DVD</b></h1>
    </head>
    <body>
    <form action="add_dvd.do" method="POST">
    Title:<input type="text" name="title" />
    Year:<input type="text" name="year" />
    Genre: <select name='gselected'>
    <option value='Sci-Fi'>Sci-Fi</option>
    </select>
    or enter new genre:<input type="text" name='gentered' value="" />
    <input type="submit" value="Add DVD" />
    </form>
    </body>
    </html>
    and here is the servlet code:
    public class AddDVDServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    // System.out.println("in AddDVDServlet post method");
    List errorMsgs = new LinkedList();
    //retrieve form parameters
    try{
    String title = request.getParameter("title").trim();
    String year = request.getParameter("year").trim();
    *String gentered = request.getParameter("gentered");
    String gselected = request.getParameter("gselected");
    String genre="";
    if("".equals(gentered))
    genre = gselected;
    else
    genre = gentered;
    // System.out.println("parameter retrieved");
    if(!year.matches("\\d\\d\\d\\d"))
    // System.out.println("year not 4 digit long");
    errorMsgs.add("Year must be four digit long");
    if("".equals(title))
    // System.out.println("title not entered");
    errorMsgs.add("Please enter the title of the dvd");
    if("".equals(genre))
    // System.out.println("genre not valid");zdf
    errorMsgs.add("Enter genre.");
    if(! errorMsgs.isEmpty())
    //System.out.println("errors in entry ");
    request.setAttribute("errors",errorMsgs);
    // System.out.println("error attribute set in request");
    RequestDispatcher rd = request.getRequestDispatcher("error.view");
    rd.forward(request, response);
    return;
    //create DVDItem instance
    DVDItem dvd = new DVDItem(title,year,genre);
    request.setAttribute("dvdItem",dvd);
    RequestDispatcher rd = request.getRequestDispatcher("success.view");
    rd.forward(request, response);
    catch(Exception e){
    errorMsgs.add(e.getMessage());
    request.setAttribute("errors",errorMsgs);
    RequestDispatcher rd = request.getRequestDispatcher("error.view");
    rd.forward(request, response);
    e.printStackTrace();
    System.out.println("exception:"+e);
    why does getParameter always return null??? whats wrong?

    I don't know. However, I suspect that because you have a tag with the same name as 'title', its causing a name conflict. Chnage the name to something else. If it works, then that's the likely explaination.

  • When I click on a result of a Google search and then go that web site, the Back button on the toolbar is grayed out and I cannot return to the search results.

    When using FF3.6 and making a Google search, when I click on a result and then go that web site, the Back button on the toolbar is grayed out and I cannot return to the search results without going to History. This does not happen all the time; about 1/2 of the time.
    This problem is not limited to Google, but occurs with other sites as well.

    If you are talking about searches from - http://www.google.com/ - are you logged into a Google account all the time? If so, check your "Search Settings" from the "gear" in the upper-right corner of that Google search page and see if you have '''Open search results in a new browser window.''' check-marked, at the bottom of that preferences page. When that is check-marked and you have Tab options in Firefox set to '''Open new windows in a new tab instead''', you will get search results always opening in a new tab instead of the same tab. As to why that works different for "sponsored links" I don't know, I haven't seen the "sponsored links" for years now, I have a GM script that blocks those advertisements.

  • Global Temp Table, always return  zero records

    I call the procedure which uses glbal temp Table, after executing the Proc which populates the Global temp table, i then run select query retrieve the result, but it alway return zero record. I am using transaction in order to avoid deletion of records in global temp table.
    whereas if i do the same thing in SQL navigator, it works
    Cn.ConnectionString = Constr
    Cn.Open()
    If FGC Is Nothing Then
    Multiple = True
    'Search by desc
    'packaging.pkg_msds.processavfg(null, ActiveInActive, BrandCode, Desc, Itemtype)
    SQL = "BEGIN packaging.pkg_msds.processavfg(null,'" & _
    ActiveInActive & "','" & _
    BrandCode & "','" & _
    Desc & "','" & _
    Itemtype & "'); end;"
    'Here it will return multiple FGC
    'need to combine them
    Else
    'search by FGC
    SQL = "BEGIN packaging.pkg_msds.processavfg('" & FGC & "','" & _
    ActiveInActive & "','" & _
    BrandCode & "',null,null); end;"
    'will alway return one FGC
    End If
    ' SQL = " DECLARE BEGIN rguo.pkg_msds.processAvedaFG('" & FGC & "'); end;"
    Stepp = 1
    Cmd.Connection = Cn
    Cmd.CommandType = Data.CommandType.Text
    Cmd.CommandText = SQL
    Dim Trans As System.Data.OracleClient.OracleTransaction
    Trans = Cn.BeginTransaction()
    Cmd.Transaction = Trans
    Dim Cnt As Integer
    Cnt = Cmd.ExecuteNonQuery
    'SQL = "SELECT rguo.pkg_msds.getPDSFGMass FROM dual"
    SQL = "select * from packaging.aveda_mass_XML"
    Cmd.CommandType = Data.CommandType.Text
    Cmd.CommandText = SQL
    Adp.SelectCommand = Cmd
    Stepp = 2
    Adp.Fill(Ds)
    If Ds.Tables(0).Rows.Count = 0 Then
    blError = True
    BlComposeXml = True
    Throw New Exception("No Record found for FGC(Finished Good Code=)" & FGC)
    End If
    'First Row, First Column contains Data as XML
    Stepp = 0
    Trans.Commit()

    Hi,
    This forum is for Oracle's Data Provider and you're using Microsoft's, but I was curious so I went ahead and tried it. It works fine for me. Here's the complete code I used, could you point out what are you doing differently?
    Cheers,
    Greg
    create global temporary table abc_tab(col1 varchar2(10));
    create or replace procedure ins_abc_tab(v1 varchar2) as
    begin
    insert into abc_tab values(v1);
    end;
    using System;
    using System.Data;
    using System.Data.OracleClient;
    class Program
        static void Main(string[] args)
            OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger");
            con.Open();
            OracleTransaction txn = con.BeginTransaction();
            OracleCommand cmd = new OracleCommand("begin ins_abc_tab('foo');end;", con);
            cmd.Transaction = txn;
            cmd.ExecuteNonQuery();
            cmd.CommandText = "select * from abc_tab";
            OracleDataAdapter da = new OracleDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Console.WriteLine("rows found: {0}", ds.Tables[0].Rows.Count);
            // commit, cleanup, etc ommitted for clarity
    }

  • Call thirty party java web service but always return null

    hi
    I call a java web service in my application visual studio 2008 c#, but always return NULL.
    I used Tool Fiddler to monitor the traffic between my client and the web service server, it showed the return is not Null.
    Here is my code, please see if anything I do wrong.
    namespace CanOfficer_THQ_vs_IHQ.TestWebReferenceAppointment {
    using System.Diagnostics;
    using System.Web.Services;
    using System.ComponentModel;
    using System.Web.Services.Protocols;
    using System;
    using System.Xml.Serialization;
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="AppointmentServiceSoapBinding", Namespace="http://service.ips.salvationarmy.org/")]
    public partial class AppointmentService : Microsoft.Web.Services3.WebServicesClientProtocol {
    private System.Threading.SendOrPostCallback deleteAppOperationCompleted;
    private System.Threading.SendOrPostCallback importAppOperationCompleted;
    private System.Threading.SendOrPostCallback editAppOperationCompleted;
    private bool useDefaultCredentialsSetExplicitly;
    /// <remarks/>
    public AppointmentService() {
    this.Url = global::CanOfficer_THQ_vs_IHQ.Properties.Settings.Default.CanOfficer_THQ_vs_IHQ_TestWebReferenceAppointment_AppointmentService;
    if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
    this.UseDefaultCredentials = true;
    this.useDefaultCredentialsSetExplicitly = false;
    else {
    this.useDefaultCredentialsSetExplicitly = true;
    public new string Url {
    get {
    return base.Url;
    set {
    if ((((this.IsLocalFileSystemWebService(base.Url) == true)
    && (this.useDefaultCredentialsSetExplicitly == false))
    && (this.IsLocalFileSystemWebService(value) == false))) {
    base.UseDefaultCredentials = false;
    base.Url = value;
    public new bool UseDefaultCredentials {
    get {
    return base.UseDefaultCredentials;
    set {
    base.UseDefaultCredentials = value;
    this.useDefaultCredentialsSetExplicitly = true;
    /// <remarks/>
    public event deleteAppCompletedEventHandler deleteAppCompleted;
    /// <remarks/>
    public event importAppCompletedEventHandler importAppCompleted;
    /// <remarks/>
    public event editAppCompletedEventHandler editAppCompleted;
    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute(
    RequestNamespace="http://service.ips.salvationarmy.org/",
    ResponseNamespace="http://service.ips.salvationarmy.org/",
    Use=System.Web.Services.Description.SoapBindingUse.Encoded,
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string deleteApp([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] int id) {
    object[] results = this.Invoke("deleteApp", new object[] {
    id});
    return ((string)(results[0]));
    /// <remarks/>
    public void deleteAppAsync(int id) {
    this.deleteAppAsync(id, null);
    /// <remarks/>
    public void deleteAppAsync(int id, object userState) {
    if ((this.deleteAppOperationCompleted == null)) {
    this.deleteAppOperationCompleted = new System.Threading.SendOrPostCallback(this.OndeleteAppOperationCompleted);
    this.InvokeAsync("deleteApp", new object[] {
    id}, this.deleteAppOperationCompleted, userState);
    private void OndeleteAppOperationCompleted(object arg) {
    if ((this.deleteAppCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.deleteAppCompleted(this, new deleteAppCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute(
    RequestNamespace="http://service.ips.salvationarmy.org/",
    ResponseNamespace="http://service.ips.salvationarmy.org/",
    Use=System.Web.Services.Description.SoapBindingUse.Encoded,
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string importApp(
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] int person,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string name,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string territory,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string location,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] bool primary,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] Nullable<System.DateTime> start,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] Nullable<System.DateTime> end,
    [System.Xml.Serialization.XmlElementAttribute("categories", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string[] categories) {
    object[] results = this.Invoke("importApp", new object[] {
    person,
    name,
    territory,
    location,
    primary,
    start,
    end,
    categories});
    return ((string)(results[0]));
    /// <remarks/>
    public void importAppAsync(int person, string name, string territory, string location, bool primary, Nullable<System.DateTime> start, Nullable<System.DateTime> end, string[] categories) {
    this.importAppAsync(person, name, territory, location, primary, start, end, categories, null);
    /// <remarks/>
    public void importAppAsync(int person, string name, string territory, string location, bool primary, Nullable<System.DateTime> start, Nullable<System.DateTime> end, string[] categories, object userState) {
    if ((this.importAppOperationCompleted == null)) {
    this.importAppOperationCompleted = new System.Threading.SendOrPostCallback(this.OnimportAppOperationCompleted);
    this.InvokeAsync("importApp", new object[] {
    person,
    name,
    territory,
    location,
    primary,
    start,
    end,
    categories}, this.importAppOperationCompleted, userState);
    private void OnimportAppOperationCompleted(object arg) {
    if ((this.importAppCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.importAppCompleted(this, new importAppCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute(
    RequestNamespace="http://service.ips.salvationarmy.org/",
    ResponseNamespace="http://service.ips.salvationarmy.org/",
    Use=System.Web.Services.Description.SoapBindingUse.Encoded,
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string editApp(
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] int id,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string name,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string territory,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string location,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] bool primary,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] Nullable<System.DateTime> start,
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] Nullable<System.DateTime> end,
    [System.Xml.Serialization.XmlElementAttribute("categories", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string[] categories) {
    object[] results = this.Invoke("editApp", new object[] {
    id,
    name,
    territory,
    location,
    primary,
    start,
    end,
    categories});
    return ((string)(results[0]));
    /// <remarks/>
    public void editAppAsync(int id, string name, string territory, string location, bool primary, Nullable<System.DateTime> start, Nullable<System.DateTime> end, string[] categories) {
    this.editAppAsync(id, name, territory, location, primary, start, end, categories, null);
    /// <remarks/>
    public void editAppAsync(int id, string name, string territory, string location, bool primary, Nullable<System.DateTime> start, Nullable<System.DateTime> end, string[] categories, object userState) {
    if ((this.editAppOperationCompleted == null)) {
    this.editAppOperationCompleted = new System.Threading.SendOrPostCallback(this.OneditAppOperationCompleted);
    this.InvokeAsync("editApp", new object[] {
    id,
    name,
    territory,
    location,
    primary,
    start,
    end,
    categories}, this.editAppOperationCompleted, userState);
    private void OneditAppOperationCompleted(object arg) {
    if ((this.editAppCompleted != null)) {
    System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
    this.editAppCompleted(this, new editAppCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
    /// <remarks/>
    public new void CancelAsync(object userState) {
    base.CancelAsync(userState);
    private bool IsLocalFileSystemWebService(string url) {
    if (((url == null)
    || (url == string.Empty))) {
    return false;
    System.Uri wsUri = new System.Uri(url);
    if (((wsUri.Port >= 1024)
    && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
    return true;
    return false;
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    public delegate void deleteAppCompletedEventHandler(object sender, deleteAppCompletedEventArgs e);
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class deleteAppCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    private object[] results;
    internal deleteAppCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
    base(exception, cancelled, userState) {
    this.results = results;
    /// <remarks/>
    public string Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((string)(this.results[0]));
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    public delegate void importAppCompletedEventHandler(object sender, importAppCompletedEventArgs e);
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class importAppCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    private object[] results;
    internal importAppCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
    base(exception, cancelled, userState) {
    this.results = results;
    /// <remarks/>
    public string Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((string)(this.results[0]));
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    public delegate void editAppCompletedEventHandler(object sender, editAppCompletedEventArgs e);
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.5483")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class editAppCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    private object[] results;
    internal editAppCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
    base(exception, cancelled, userState) {
    this.results = results;
    /// <remarks/>
    public string Result {
    get {
    this.RaiseExceptionIfNecessary();
    return ((string)(this.results[0]));

    Hi;
    I used Fiddler to monitor the process, and it showed the request sent thru web service worked and returned a value, but in my .Net application the return captured as NULL. Could you please look into the code above and the result from Filddler and see if
    you can help.
    thank you.
    REQUEST:
    POST https://159.253.140.178/services/AppointmentService HTTP/1.1
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.4252)
    Content-Type: text/xml; charset=utf-8
    SOAPAction: ""
    Host: 159.253.140.178
    Content-Length: 1589
    Expect: 100-continue
    Connection: Keep-Alive
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://service.ips.salvationarmy.org/" xmlns:types="http://service.ips.salvationarmy.org/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
    <soap:Header>
    <wsse:Security mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:Username>
    [email protected]
    </wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
    tpi4IPSws!
    </wsse:Password>
    </wsse:UsernameToken>
    </wsse:Security>
    </soap:Header>
    <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <tns:importApp>
    <person xsi:type="xsd:int">
    169275
    </person>
    <name xsi:type="xsd:string">
    Corps Officer (Cahul-Russia) Test12
    </name>
    <territory xsi:type="xsd:string">
    CAN
    </territory>
    <location xsi:type="xsd:string">
    TEST LOCATION 12
    </location>
    <primary xsi:type="xsd:boolean">
    true
    </primary>
    <start xsi:type="xsd:dateTime">
    2013-05-30T00:00:00
    </start>
    <end xsi:type="xsd:dateTime">
    2014-06-04T00:00:00
    </end>
    <categories href="#id1" />
    </tns:importApp>
    <soapenc:Array id="id1" soapenc:arrayType="xsd:string[1]">
    <Item>
    vpsCat1
    </Item>
    </soapenc:Array>
    </soap:Body>
    </soap:Envelope>
    RESPONSE:
    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Content-Type: text/xml;charset=UTF-8
    Content-Length: 232
    Date: Fri, 05 Sep 2014 19:45:22 GMT
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <ns2:importAppResponse xmlns:ns2="http://service.ips.salvationarmy.org/">
    <return>
    OK_572463
    </return>
    </ns2:importAppResponse>
    </soap:Body>
    </soap:Envelope>

  • Call C# method from javascript in WebView and retrieve the return value

    The issue I am facing is the following :
    I want to call a C# method from the javascript in my WebView and get the result of this call in my javascript.
    In an WPF Desktop application, it would not be an issue because a WebBrowser
    (the equivalent of a webView) has a property ObjectForScripting to which we can assign a C# object containg the methods we want to call from the javascript.
    In an Windows Store Application, it is slightly different because the WebView
    only contains an event ScriptNotify to which we can subscribe like in the example below :
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    this.webView.ScriptNotify += webView_ScriptNotify;
    When the event ScriptNotify is raised by calling window.external.notify(parameter), the method webView_ScriptNotify is called with the parameter sent by the javascript :
    function CallCSharp() {
    var returnValue;
    window.external.notify(parameter);
    return returnValue;
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = DoSomerthing(parameter);
    The issue is that the javascript only raise the event and doesn't wait for a return value or even for the end of the execution of webView_ScriptNotify().
    A solution to this issue would be call a javascript function from the webView_ScriptNotify() to store the return value in a variable in the javascript and retrieve it after.
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = ReturnResult();
    await this.webView.InvokeScriptAsync("CSharpCallResult", new string[] { result });
    var result;
    function CallCSharp() {
    window.external.notify(parameter);
    return result;
    function CSharpCallResult(parameter){
    result = parameter;
    However this does not work correctly because the call to the CSharpResult function from the C# happens after the javascript has finished to execute the CallCSharp function. Indeed the
    window.external.notify does not wait for the C# to finish to execute.
    Do you have any solution to solve this issue ? It is quite strange that in a Window Store App it is not possible to get the return value of a call to a C# method from the javascript whereas it is not an issue in a WPF application.

    I am not very familiar with the completion pattern and I could not find many things about it on Google, what is the principle? Unfortunately your solution of splitting my JS function does not work in my case. In my example my  CallCSharp
    function is called by another function which provides the parameter and needs the return value to directly use it. This function which called
    CallCSharp will always execute before an InvokeScriptAsync call a second function. Furthermore, the content of my WebView is used in a cross platforms context so actually my
    CallCSharp function more look like the code below.
    function CallCSharp() {
    if (isAndroid()) {
    //mechanism to call C# method from js in Android
    //return the result of call to C# method
    } else if (isWindowsStoreApp()) {
    window.external.notify(parameter);
    // should return the result of call to C# method
    } else {
    In android, the mechanism in the webView allows to return the value of the call to a C# method, in a WPF application also. But I can't figure why for a Windows Store App we don't have this possibility.

Maybe you are looking for