Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create a food order system at the restaurant using the android and WPF. so the waiter will use Android to transmit data to the Server(with ip) using wifi. and there is a wpf app in the server and which listening to a particular port.

for easier to test i am run both the android(in bluestack) and wpf app in same system.but unfortunately i did not get the data in wpf app.my code will attach here.

the main problem is am unable to find error whether the error is in android side or in wpf side.

android (client)

Java
    //am already created the xml data and converted it to string(that code is not added here)
                        TransformerFactory factory = TransformerFactory.newInstance();
			Transformer transformer = factory.newTransformer();
			Properties outFormat = new Properties();
			outFormat.setProperty(OutputKeys.INDENT, "yes");
			outFormat.setProperty(OutputKeys.METHOD, "xml");
			outFormat.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
			outFormat.setProperty(OutputKeys.VERSION, "1.0");
			outFormat.setProperty(OutputKeys.ENCODING, "UTF-8");
			transformer.setOutputProperties(outFormat);
			DOMSource domSource = new DOMSource(document.getDocumentElement());
			OutputStream output = new ByteArrayOutputStream();
			StreamResult result = new StreamResult(output);
			transformer.transform(domSource, result);
			xmlString = output.toString(); 
    //only small portion of the xml creation is added here

    //xml sending
    final DefaultHttpClient httpClient = new DefaultHttpClient();

        final HttpPost httppost = new HttpPost("http://10.0.2.2:9900/cogglrestservice.svc/InsertTrack");     
        // Make sure the server knows what kind of a response we will accept
        httppost.addHeader("Accept", "text/xml");
        // Also be sure to tell the server what kind of content we are sending
        httppost.addHeader("Content-Type", "application/xml");

        try
        {
        StringEntity entity = new StringEntity(xmlString, "UTF-8");
        entity.setContentType("application/xml");
        httppost.setEntity(entity);
         new Thread(new Runnable() {
            public void run() {
            	 // execute is a blocking call, it's best to call this code in a thread separate from the ui's
                try {
					response = httpClient.execute(httppost);
				} catch (ClientProtocolException e) {
					// TODO Auto-generated catch block
					Log.e("message",Log.getStackTraceString(e));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					Log.e("message",Log.getStackTraceString(e));
				}
                    }
                }).start(); 
          BasicResponseHandler responseHandler = new BasicResponseHandler();
           String strResponse = null;
           if (response != null) {
               try {
                   strResponse = responseHandler.handleResponse(response);
               } catch (HttpResponseException e) {
            	   Log.e("message",Log.getStackTraceString(e));
               } catch (IOException e) {
            	   Log.e("message",Log.getStackTraceString(e));
               }
           }
           Log.e("WCFTEST", "WCFTEST ********** Response" + strResponse);    
        }
        catch (Exception ex)
        {
       // ex.printStackTrace();
        	Log.e("message",Log.getStackTraceString(ex));
        Toast.makeText(OrderlistActivity.this, ex.getMessage(),Toast.LENGTH_SHORT).show();
        }
        Toast.makeText(OrderlistActivity.this, "Xml posted succesfully.",Toast.LENGTH_SHORT).show();
	}
}



wpf (server) section (App.config)

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <!-- This section is optional with the new configuration model introduced in .NET Framework 4. -->
      <service name="SmartMenu_Kitchen.GetOrder" behaviorConfiguration="NotificationServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1:9900/Notifier/service"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" contract="SmartMenu_Kitchen.INotifyClient" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NotificationServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>


wpf class file to accept xml

C#
namespace SmartMenu_Kitchen
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public ServiceHost objServiceHost = null;

        public MainWindow()
        {
            InitializeComponent();

            // UPDATE THE DELEGATE OF YOUR SERVICE HERE.
            GetOrder.UIUpdater = ShowOrder;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (objServiceHost != null)
                {
                    objServiceHost.Close();
                }

                // CREATE A SERVICEHOST FOR THE SERVICE TYPE AND PROVIDE THE BASE ADDRESS.
                objServiceHost = new ServiceHost(typeof(GetOrder));

                // OPEN THE SERVICEHOSTBASE TO CREATE LISTENERS AND START LISTENING FOR MESSAGES.
                objServiceHost.Open();
            }
            catch (Exception ex)
            {

                throw;
            }
        }

        public void ShowOrder(object sender, UpdateUIEventArgs e)
        {


            // USE INVOKE() TO MAKE SURE THE UI INTERACTION HAPPENS
            // ON THE UI THREAD...JUST IN CASE THIS DELEGATE IS
            // INVOKED ON ANOTHER THREAD.
            Dispatcher.BeginInvoke(new Action(delegate
            {


                ListView lstOrder = new ListView();
                StackPanel stackPnl = new StackPanel();
                XmlDocument xml = new XmlDocument();
                XmlNodeList xnList;

                lstOrder.Width = 300;
                lstOrder.Height = 250;
                lstOrder.FontSize = 20;
                lstOrder.FontWeight = FontWeights.Bold;

                //LOAD XML
                xml.LoadXml(e.Text);
                xnList = xml.SelectNodes("order/Items/Item");

                foreach (XmlNode xn in xnList)
                {

                    StackPanel stackPanelOrder = new StackPanel();

                    stackPanelOrder.Orientation = Orientation.Horizontal;


                    if (xn["orderType"].InnerText == "1")
                    {
                        string ItemName = xn["ItemName"].InnerText;
                        string Quantity = xn["Quantity"].InnerText;

                        TextBlock txtItemName = new TextBlock();
                        TextBlock txtQuantity = new TextBlock();

                        //SET ITEM ATTRIBUTES
                        txtItemName.Width = 220;
                        txtItemName.Text = ItemName;

                        //ADD ITEM TO PANEL
                        stackPanelOrder.Children.Add(txtItemName);

                        //SET QUANTITY ATTRIBUTES
                        txtQuantity.Width = 20;
                        txtQuantity.Text = Quantity;

                        //ADD QUANTITY TO PANEL
                        stackPanelOrder.Children.Add(txtQuantity);
                  
                        //ADD PANEL TO LIST
                        lstOrder.Items.Add(stackPanelOrder);
                       
                    }
                }

                lstOrder.Foreground = new SolidColorBrush(Colors.Green);

                XmlNodeList xnTable = xml.SelectNodes("order/orderFrom");

                foreach (XmlNode xn in xnTable)
                {
                    TextBlock txtBlockTableNumber = new TextBlock();
                    TextBlock txtBlockWaiterName = new TextBlock();

                    //ADD TABLE NUMBER
                    txtBlockTableNumber.Text = xn["TableNumber"].InnerText;
                    stackPnl.Children.Add(txtBlockTableNumber);

                    //ADD WAITER NAME
                    txtBlockWaiterName.Text = xn["WaiterName"].InnerText;
                    stackPnl.Children.Add(txtBlockWaiterName);

                }

                //ADD  PANEL COLOR RANDOMLY
                Random randomGen = new Random();
                SolidColorBrush brush = new SolidColorBrush(
                                                Color.FromRgb(
                                                (byte)randomGen.Next(255),
                                                (byte)randomGen.Next(255),
                                                (byte)randomGen.Next(255)
                                                ));

                //ADD LIST TO PANEL
                stackPnl.Children.Add(lstOrder);
                stackPnl.Background = brush;
                
                //ADD PANEL TO SCREEN
                this.wrpPanel.Children.Add(stackPnl);

            }));
        }


    }
}




android logcat after running

04-11 17:24:06.772: E/WCFTEST(1790): WCFTEST ********** Responsenull
04-11 17:53:08.182: E/WCFTEST(1790): WCFTEST ********** Responsenull


please help anyone...
Posted
Updated 11-Apr-14 2:28am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900