As it looks like you are trying to access the MBean from inside a component (like servlet/jsp...etc) from inside the JBoss. So can you try the following:
Step1). Place the "jboss-as-7.1.1.Final/bin/client/jboss-client.jar" inside the "WEB-INF/lib" directory of your application.
Step2). Now Change the code of MBean Access as following:
String host = "localhost"; // Your JBoss Bind Address default is localhost
int port = 9999; // management-native port
String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;
System.out.println(" \n\n\t**** urlString: "+urlString);
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
//Invoke on the JBoss AS MBean server
int count = connection.getMBeanCount();
ObjectName objectName=new ObjectName("myproject.service.Test:service=com.mytest.program");
This is just to test whether the Mbean which you created if fine or If it is deployed successfully or not... You can also try using the JCOnsole to see if you are able to see your Custom MBean in the JConsole MBeans tab.