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)
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();
final DefaultHttpClient httpClient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("http://10.0.2.2:9900/cogglrestservice.svc/InsertTrack");
httppost.addHeader("Accept", "text/xml");
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() {
try {
response = httpClient.execute(httppost);
} catch (ClientProtocolException e) {
Log.e("message",Log.getStackTraceString(e));
} catch (IOException e) {
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)
{
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)
="1.0"="utf-8"
<configuration>
<system.serviceModel>
<services>
<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
namespace SmartMenu_Kitchen
{
public partial class MainWindow : Window
{
public ServiceHost objServiceHost = null;
public MainWindow()
{
InitializeComponent();
GetOrder.UIUpdater = ShowOrder;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
if (objServiceHost != null)
{
objServiceHost.Close();
}
objServiceHost = new ServiceHost(typeof(GetOrder));
objServiceHost.Open();
}
catch (Exception ex)
{
throw;
}
}
public void ShowOrder(object sender, UpdateUIEventArgs e)
{
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;
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();
txtItemName.Width = 220;
txtItemName.Text = ItemName;
stackPanelOrder.Children.Add(txtItemName);
txtQuantity.Width = 20;
txtQuantity.Text = Quantity;
stackPanelOrder.Children.Add(txtQuantity);
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();
txtBlockTableNumber.Text = xn["TableNumber"].InnerText;
stackPnl.Children.Add(txtBlockTableNumber);
txtBlockWaiterName.Text = xn["WaiterName"].InnerText;
stackPnl.Children.Add(txtBlockWaiterName);
}
Random randomGen = new Random();
SolidColorBrush brush = new SolidColorBrush(
Color.FromRgb(
(byte)randomGen.Next(255),
(byte)randomGen.Next(255),
(byte)randomGen.Next(255)
));
stackPnl.Children.Add(lstOrder);
stackPnl.Background = brush;
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...