|
Ive followed this guide: http://studentguru.gr/b/dt008/archive/2010/12/02/querying-a-database-on-windows-phone-7-using-wcf.aspx[^]
I have tree different entries in my SQL and then i launch my application I get tree entries but they are all a copy of the first one.
CODE:
NSSService which is on my ISS.
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
namespace NSSWebServiceApplication
{
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NSSService
{
[OperationContract]
public List<Server_Log> GetAllServer_Logs()
{
using (NSSEntities entities = new NSSEntities())
{
var allServer_Logs = from x in entities.Server_Log
select x;
return allServer_Logs.ToList();
}
}
}
}
MainPage on the app
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using NSSPhoneApp.NSSServiceReference;
using System.ServiceModel;
namespace NSSPhoneApp
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
NSSServiceClient client = new NSSServiceClient();
client.GetAllServer_LogsCompleted +=
new EventHandler<GetAllServer_LogsCompletedEventArgs>(client_GetAllServer_LogsCompleted);
client.GetAllServer_LogsAsync();
}
void client_GetAllServer_LogsCompleted(object sender, GetAllServer_LogsCompletedEventArgs e)
{
if (e.Error == null)
{
lst.ItemsSource = e.Result;
}
}
}
}
Thanks.
|
|
|
|
|
It was because there was no primary key in the SQL so it used my status as the primary key.
|
|
|
|
|
May I know how can I convert a decimal (eg: 0.3333) to percent format.
I have tried with this code:
ws.Cells[1,1].Value = 0.3333;
ws.Cells[1.1].Style.Numberformat.Format = "0%";
But this give me 33% instead of 33.33%
|
|
|
|
|
Did you try "0.00%"?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
It's work! Thank you so much.
|
|
|
|
|
double t = 0.3333;
Console.WriteLine(t.ToString("##.##%"));
|
|
|
|
|
I have a program which allows user to input a sequence of numbers. The length of the number is not fixed. It could be 10, 12, or whatever length.
After the user has finished inputting the number, I want the program to automatically scan the database and return information about that number.
Question is how? If I use TextChanged() event, it is called whenever every character is typed. I only want to know when the last character is typed.
Please help. I have spent many days on this already.
|
|
|
|
|
Hi,
Can't you use LostFocus event, when user finish with typing and press TAB key it will search for the result.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
I second Amit's suggestion of using the Leave event. If for some reason your requirements are not going to allow you to ( I don't see why ), you could always just have the TextChanged event do nothing until the length of the entered text is greater than or equal to 10.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Store the current time in a class level field in the TextChanged event. Run a timer every 1 second (or 2 seconds if you prefer) and inside the Timer's Elapsed event handler (or Tick event handler depending on which Timer you use) check when the last character was typed, if it is more than 1 second, it's time to do your stuff.
|
|
|
|
|
biop.codeproject wrote: I want the program to automatically scan the database and return
information about that number.
Really bad idea.
How exactly are you going to deal with ALL of the following scenarios if you attempt to guess when they are done?
1. User types 120 words a minute which is 2 characters a second. So it takes them at most 6 seconds to type the number.
2. Same EXACT user as above. But they are reading the number from a piece of paper and when they get to the 6th digit they can't read it. So they go down the hallway to ask another person what it is. And they don't return for 15 minutes.
3. The user is physically disabled and it takes them 3 minutes to type those 12 digits with different periods of delay between each character.
The only solution is that the user must take some action AFTER they are finished typing. Like pushing an ok button, hitting return, or tabbing to another field.
|
|
|
|
|
Let's break your problem down here. You have a sequence of some length that you don't know. The user enters numbers into a TextBox, again you don't know how long this sequence is. How do you know when the last character is entered?
Your user experience is going to have to be one of:
User enters sequence and leaves the field - at which point you retrieve the matching entry and display it if found.
User enters sequence and as each character is pressed, possible matches are retrieved from the database and displayed (a standard autocomplete). The user can select one of these elements and the text sequence is updated.
User enters sequence and clicks some form of button to trigger the retrieval.
Without knowing how long this sequence is going to be, you cannot do anything other.
|
|
|
|
|
Thanks for all your input. Actually yes that is true, without knowing the number of characters to be entered in advance, it could be an impossible task.
Actually the input is from two devices. One is from scanning RFID (a 24 character string) and another is from barcode (this is harder as I don't know the predefined limit).
Lucky I can capture the event that the RFID scanner button is pressed and the barcode scanner button is pressed.
Now I am integrating the two sample programs together. Hope it works. And I consider this question is closed. Thanks.
|
|
|
|
|
A work, I have just been assigned to consume a web service using C# 2010. The web service is suppose to give me a list of customer ids. I need to obtain the list of customer ids by working with an .xsd file. (By look at the documentation for the xsd file, it looks like xml to me.) In addition from this web service, I obtain suppose to obtain files that I can download that are in word, pds, and tiff formats.
By the way, I know that I can connect to the web service since I have a command script, that can connect to ther web service. (The command script was written by the company that wrote the web service.)
Due to the requirements listed above, I am wondering if you can tell me the following:
1. How to connect a C# console, desktop, and/or web app to the web service?
2. How can I obtain the xsd file from the web service and transverse the xsd file to obtain the data I am looking for?
3. How can I download the word document, pdf, and/or tiff file from the web service?
|
|
|
|
|
classy_dog wrote: How to connect a C# console, desktop, and/or web app to the web service?
It depends on the type of web service, but if it's a Microsoft SOAP web service, you should be able to get info about it by visiting the WSDL page for it. So, if the web service is:
site.com/SomeService.asmx
You can view the WSDL at:
site.com/SomeService.asmx?wsdl
Also, it mostly doesn't matter what type of app you are making... they all connect to web services the same way. However, if you are connecting via JavaScript, that is different and introduces some security considerations.
In general, you connect to a web service using a proxy class. There are a couple ways to generate one. For one, you can "add a service reference" in Visual Studio, and that will create the proxy class for you. I prefer to use a the WSDL.exe command line tool. To use it, you must first open the Visual Studio command prompt:
Start... All Programs... Microsoft Visual Studio 2010... Visual Studio Tools... Visual Studio Command Prompt (2010)
You then type "wsdl.exe /?" to see how to use it. However, taking our example, you could type this:
wsdl.exe /langauge:cs /namespace:Whatevs /out:C:\SomeServiceProxy.cs http://www.site.com/SomeService.asmx?wsdl
I forget if you actually need to type in the "?wsdl" or not. If it works, you should see a file on your C: drive called SomeServiceProxy.cs. It should be a C# class in the "Whatevs" namespace. Bring this file into your Visual Studio project, create an instance of the class, and you should be able to call methods on it just like any normal method (e.g., SomeServiceProxy.GetCustomerIDs() ). The proxy class hides the web service details... instances of classes are returned, so you never need to mess with the icky details like serialization and deserialization. .Net web service proxy classes handle this for you.
classy_dog wrote: How can I obtain the xsd file from the web service and transverse the xsd file to obtain the data I am looking for?
I forget what the difference is between XSD and WSDL, but I think XSD is the old version or something like that (or maybe an alternative format). If you create a proxy class, however, you shouldn't have to worry about XSDs and WSDLs.
classy_dog wrote: How can I download the word document, pdf, and/or tiff file from the web service?
Files will probably be returned from a web service as a byte array. Other info, like the filename, may also be returned (in the case of a filename, it would be returned as a string). Save the byte array to a file and you are good to go. If you are returning the file from a webpage, that's a little different, but not much (e.g., you'll have to add some HTTP headers and such).
By the way, if this is all overwhelming, I recommend buying a book that describes how to use web services. I read one that was called something like "SOA in .Net" (SOA meaning Service Oriented Architecture). If you consider things like security and alternative architectures (e.g., REST), it can get complicated.
|
|
|
|
|
I have the additional comments/questions to ask:
1 When I call the web service and ask for a document, the web service places the document in a directory path that I specify in an app.config file for the console application I just started to write. I always receive the file in a PDF format and not in a word document format. Thus if I want to convert the PDF file to a word document, I probably need to do the conversation after I rewceive the file, correct? If I am wrong, how would I accomplish this goal?
2. when I call the web service and from a command dos prompt, I have been directing the output to a text file for now. However the output I receive is the command I wrote plus the xsd file response. I know that I will need obtain the response in another way besides redirecting the output to a text file. Thus can you tell me how I can save the xsd file format reponse? In addition, can you tell me how I can determine how to parse the xsd results so I can obtain the data I am looking for?
|
|
|
|
|
1) I don't know what the web service is capable of, so I suppose if you want the PDF as a word doc, then you'll have to convert it.
2) I'm not sure what you're doing, but it doesn't sound like you're calling the service via a proxy class. If you're doing something custom, I can't help you. Though, I am pretty sure an XSD isn't supposed to contain actual data... just shows the format of what data can be returned.
|
|
|
|
|
If you have the data contract (the xsd file), you can generate the code that you need for the data types using this[^] product. However, from the xsd, you don't get the operations that can be performed, you merely get the data structures. You are going to need to write the code to interact with the operations yourself.
classy_dog wrote: 1. How to connect a C# console, desktop, and/or web app to the web service?
WSCF.blue will give you the ability to generate the service reference code.
classy_dog wrote: 2. How can I obtain the xsd file from the web service and transverse the xsd
file to obtain the data I am looking for?
You already have the xsd file. You just said so.
classy_dog wrote: 3. How can I download the word document, pdf, and/or tiff file from the web
service?
You don't. You get whatever representation of these that the service returns (possibly a base 64 encoded string) and convert that at your end and save to disk.
|
|
|
|
|
classy_dog wrote: need to obtain the list of customer ids by working with an .xsd file
The xsd is a definition of what the xml will look like. Thus you don't get the ids from an xsd source.
|
|
|
|
|
Hi
Has anyone tried to access Comupter Associates ( CA) TOP-SECRET thru LDAP in C# code. If yes please respond as I would like to get some specific info to do the resource permissions checks.
Thanks, Ravi
|
|
|
|
|
Considering the verticle nature of your request, more than likely not.
The best place to ask about using a particular library or product is the manufacturer of the library or product.
|
|
|
|
|
I'm having a tough time converting month, day, and year into hex then byte[]. I did an internet search and I'm not finding anything that is similar enough to provide the link to. This is what I have so far from before I realized I needed the hex, but I do need the 2-digit mo/day/yr before it's hex. I'm a little confused about converting to hex since I would normally take the number and use ToString("X"), but it doesn't seem to apply here since I'm applying the formatting to get it to the 2-digit month, for example.
DateTime mfg = DateTime.Now;
mfgDate_mo = new byte[mfg.ToString("MM").Length * sizeof(char)];
convertStringToByteArr(mfg.ToString("MM"), ref mfgDate_mo);
mfgDate_dy = new byte[mfg.ToString("dd").Length * sizeof(char)];
convertStringToByteArr(mfg.ToString("dd"), ref mfgDate_dy);
mfgDate_yr = new byte[mfg.ToString("yy").Length * sizeof(char)];
convertStringToByteArr(mfg.ToString("yy"), ref mfgDate_yr);
private void convertStringToByteArr(String theString, ref byte[] theByteArr)
{
System.Buffer.BlockCopy(theString.ToCharArray(), 0, theByteArr, 0, theByteArr.Length);
}
|
|
|
|
|
I'm sorry, but your description doesn't make much sense to me. I've read it a couple of times and I can't visualise what you are trying to do. Given an input of todays date, what are you expecting to see in the byte array? If you could illustrate this, then perhaps I can help.
|
|
|
|
|
For example, today's date is 8/20/2012. I need to take the 8, represent it as 08, convert it to Hex which is still 08 for that one, then put it in a byte array. For the year, I need to take the 12, which is already 2 digits, then convert to hex, which is 0C, then put it in byte array.
|
|
|
|
|
So just use the following to convert:
private byte[] Convert(int datePart)
{
string convertedPart = datePart.ToString("X2");
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
return enc.GetBytes(convertedPart);
}
|
|
|
|
|