|
Here is the description of the issue:
I am trying to develop an application in C#. Then, somewhere in the application, I will need to send an XML file to .NET Web Service so the Web Service can process the XML and store it in the database.
I couldn't figure out how to send an XML file to .NET Web Service. Does anyone know how to do it?
Any suggestions along with sample code will be appreciated.
|
|
|
|
|
|
you can send as xmlnode object.
InClient
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode cx = doc1.SelectSingleNode("/rootnode");
ret = myser.XmlFile(cx);
In WebService
XmlFile(XmlNode XmlNodePassed)
{
xdo.LoadXml( XmlNodePassed.OuterXml);
}
|
|
|
|
|
HI Friends,
I have a problem regarding, Users of the Computer.
See, i have to find out the User which is currently login with the System through C#.NET
How i am getting to this?
Please if u have a solution then reply this.
|
|
|
|
|
Hi, see Environment.UserName.
|
|
|
|
|
The easiest way is to use Environment.UserName
But if you logged in in a domain server, then you
must use this one to see the domain. For example
MYDOMAIN\myusername
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
Console.WriteLine(wp.Identity.Name);
|
|
|
|
|
Request.ServerVariables["LOGON_USER"];
|
|
|
|
|
hi i want to change the width of excel column but it gives error that cannt change read only property,i m using code below
ws.Row[1,2].Entirecolmn.widht=12;//gives error?
Tasleem Arif
|
|
|
|
|
Try recording macro in Excel, and use same code.
My english is bad. Please, correct my errors.
Best regards, Alexey.
|
|
|
|
|
I've searched the internet for info on this...and i've seen that everyone's code is like that in this msdn article: http://msdn2.microsoft.com/en-us/library/ms223898.aspx
When trying to catch all unhandled thread exceptions that an application can give, the function at the end of this event:
Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);
is never called (see code in that msdn article)...also to test that code you need a windows application project with form with two buttons wired to the actions in the articles code...
So on one site i saw someone say its that because a debugger is installed that the thread exception will be caught by the "do you want to send error report to microsoft or debug" form and not handled by the program. Even if that's true, how to i test it without going to a computer without a debugger installed.
also note i'm not talking about executing the code in debug mode but ctrl + f5 ing it which still results in windows trying to send error report to microsoft when thread exception thrown.
|
|
|
|
|
I'm working on a simple TCP chat program. The user should be able to send messages through a LAN. However, I can't find a way to convert the string to a byte array so I can send it with the NetworkStream.Write() method. Can anyone explain me how to do it and how to do the reverse process? Thanks in advance.
overfreeze
|
|
|
|
|
Look at the System.Text.UnicodeEncoding.Unicode.GetBytes() method. There are ASCII encodings in the System.Text namespace as well if you're using ASCII only text.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
similarly u can find the encoding of the string u recieve by
System.Text.ASCIIEncoding.GetEncoding(recievedstring);
and then pay back the sender in his coins
|
|
|
|
|
Here is some C++ code I have used for this purpose before. It should be easy to convert it to C#.
private: void Send(String *msg)
{
try
{
Int32 port = 30000;
String * server = S"127.0.0.1";
TcpClient * client = new TcpClient(server, port);
Byte data[] = System::Text::Encoding::ASCII->GetBytes(msg->ToString());
NetworkStream* stream = client->GetStream();
stream->Write(data, 0, data->Length);
client->Close();
}
catch (Exception* e)
{
MessageBox::Show(e->get_Message(), "XLogoff Send Message Error");
}
}
Best,
Jun
|
|
|
|
|
I'm trying to build an application which uses more than one form
How can I keep a window activated when the user tries to activate another form from my application.
I've tryied to use sendtoback but this sends all my forms to the lowest level
What can I do?
modified 30-Nov-21 21:01pm.
|
|
|
|
|
without any sample of your code, this wuold be hard to answer.
You could try form1.Activate() immediately after the new form is shown.
|
|
|
|
|
i while doing work came up to introducing multi threading in my application but the problem in my case is that the signature of function or functions i want to execute in the thread doesnot match that of delegate "ThreadStart".
those parameter that i pass to my functions r very important i have already spend alots of time finalizing them.
so anyway out??
i will be very thankful for any kind help.
|
|
|
|
|
Have your method set members within your class and then use thread start within your method with the special parameters. Keep in mind you will have to be very careful of synchronisity when doing this but that is the method I use. (sometimes)
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
its like one class and i use local variables of a method to pass values to these method(those which r passed to ThreadStart delegate).
to put it simple and straight. its a switch case statement. in one statement i want to initiate one method and in other case statement i want to intiate an other method. so i have declared a golab Thread instance and initialize it in every case statement.
main problem is with the signature of my methods. every time i run the programe, an error appears say that
" Method 'Download(string, Testing.Form1.Data, string, string)' does not match delegate 'void System.Threading.WaitCallback(object)'"
|
|
|
|
|
Are you using C# 2? If so, you can use anonymous delegates to do this:
void Foo()
{
int val = 5;
string text = "blah";
ThreadPool.QueueUserWorkItem(delegate
{
OnAnotherThread(val, text);
});
}
void OnAnotherThread(int i, string s)
{
MessageBox.Show(s);
}
Another way--the way that the C# 2 compiler implements it under the hood--is to create a class that stores the variables you want to pass to the function, then create a function in that class whose signatures matches WaitCallback. Here's an example:
void Foo()
{
int val = 5;
string text = "blah";
HolderClass holder = new Holder(val, text);
ThreadPool.QueueUserWorkItem(holder.OnAnotherThread);
}
class HolderClass
{
private int value;
private string text;
public HolderClass(int value, string text)
{
this.value = value;
this.text = text;
}
public void OnAnotherThread(object state)
{
MessageBox.Show(this.text);
}
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
iam using VS 2003 and SDK V 1.1
its not supported in my version
|
|
|
|
|
it would be a mess if i do it with global variables. it would be my last resort. if it ever is.
|
|
|
|
|
You don't have to use global data. Instaed, you can create a wrapper class which contains your thread function and all other related methods and data members. The only constraint is that all of the methods and data members should be static. The following C++ code snippets are extracted from my CP article http://www.codeproject.com/useritems/xlogoff.asp[^]. My thread function processes lots of data within the class. One thing to note is that I used mutex to protect the data accessed by more than one thread.
Here is the OnStart() in my Windows service code, which simply starts a thread:
void OnStart(String* args[])
{
Thread *oThread = new Thread(new ThreadStart(0, &XLogoffThread::ThreadProc));
oThread->Start();
}
Here is the thread class which contains a thread function as the delegate function to ThreadStart and all other methods and data:
public __gc class XLogoffThread
{
private: static String* prevSession;
private: static String* DATA_FILE = S"session.dat";
private: static ArrayList* baseline = new ArrayList;
public: static Mutex * mut = new Mutex();
private: static SnippetsCPU::ProcessAsUser *cpau = new SnippetsCPU::ProcessAsUser();
public: static void ThreadProc()
{
try
{
if ( !File::Exists(DATA_FILE) )
{
File::Create(DATA_FILE);
}
Int32 port = 30000;
IPAddress* localAddr = IPAddress::Parse(S"127.0.0.1");
TcpListener* server = new TcpListener(localAddr, port);
Byte bytes[] = new Byte[128];
server->Start();
while (true)
{
TcpClient* client = server->AcceptTcpClient();
String* data = 0;
NetworkStream* stream = client->GetStream();
do
{
Int32 i = stream->Read(bytes, 0, bytes->Length);
data = Text::Encoding::ASCII->GetString(bytes, 0, i);
ProcessCmd(data);
} while (stream->DataAvailable);
client->Close();
}
} catch (SocketException* except)
{
MessageBox::Show( except->get_Message(), "XLogoff Service Error" );
}
}
}
Hope this helps.
Best,
Jun
|
|
|
|
|
thanx alot buddy. i will try it out.
but one thing about ur code of class XLogoffThread. it never use those static properties in the ThreadProc(). so whats the use of those fields. i asked because thats the concept iam going to implement.
|
|
|
|
|
ProcessCmd(data) and its delegates use these data. Most of the code has been omitted in the post. You might want to grab the complete code following the link in that post.
Best,
Jun
|
|
|
|