|
WebRequest.GetSystemWebProxy() doesn't work either. I still get the 407 error.
i.e.
webRequest = (HttpWebRequest)WebRequest.Create(strURL);
webRequest.Credentials = CredentialCache.DefaultCredentials;
IWebProxy wp = WebRequest.GetSystemWebProxy();
webRequest.Proxy = wp;
|
|
|
|
|
through trial-and-error I finally got it solved.
On my journey I've noticed that MANY people have problems with this, so no doubt this code will be copied plenty:
public string GetWebPage(string strURL)
{
string strResult = "";
HttpWebRequest webRequest;
webRequest = (HttpWebRequest)WebRequest.Create(strURL);
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
webRequest.Proxy = proxy;
webRequest.Method = "GET";
webRequest.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)";
webRequest.Timeout = -1;
HttpWebResponse webResponse;
webResponse = (HttpWebResponse)webRequest.GetResponse();
using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
|
|
|
|
|
this is also not working boss.M getting error
|
|
|
|
|
I get the Proxy Authentication only when using NUnit; the same code works fine when invoked in the real environment.
Anyway, adding the following lines makes it work in NUnit:
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials;
request.Proxy = proxy;
|
|
|
|
|
Hi, not sure if you're still struggling with this.
Maybe this could help... I was looking at a solution to call a web service from behind a company firewall, but I didn't want to code any proxy settings nor user credentials in my app. The app should simply use my default IE proxy settings.
I'm using .Net 2.0 and here's the C# code to make it work.
<br />
IWebProxy oProxy = WebRequest.GetSystemWebProxy();<br />
oProxy.Credentials = (System.Net.NetworkCredential)CredentialCache.DefaultCredentials;<br />
"your WS stub".Proxy = oProxy;<br />
Hope this helps.
|
|
|
|
|
Hi all,
I need help regarding how to communicate with OPCServer. I am developing an application in C#. In project Reference I added OPCAutomation 2.0(COM). I am adding the code which I done.
OPCServer MyServer = null;
OPCGroups MyOPCGroups = null;
OPCGroup MYOPCGroup = null;
MyServer = new OPCServer();
MyServer.Connect(ProgID,NODE);
// till here ok
MyOPCGroups =(OPCGroups) MyServer.OPCGroups;
// but when I tried to create the OPCGroups I am getting casting error saying:
// "Unable to cast object of type 'OPCAutomation.OPCServerClass' to type 'OPCAutomation.IOPCGroups'."
MYOPCGroup = (OPCGroup)MyOPCGroups.Add("MyGroup");
I really hope you can help me!
Regards,
Alessandro
|
|
|
|
|
Hi All,
I have a datagridview with some textbox and combobox columns. This shows some data from postgresql.
It works fine bud when im trying to set the DataPropertyName of the combobox column, im getting the error:
System.ArgumentException: The value of DatagridviewComboboxCell is invalid
Here is a part of my code:
NpgsqlCommand com = new NpgsqlCommand("SELECT tablee AS Table, columnn AS Column, sort AS Sort, " + " criteria AS Criteria, or1 AS ColOr1, or2 AS ColOr2 FROM queryfilters "+ " WHERE category='" + category + "' AND queryname='" + descr + "' AND modifier='"+modifier+"'", mycon); NpgsqlDataAdapter da = new NpgsqlDataAdapter(com); DataTable dt = new DataTable(); BindingSource bs = new BindingSource(); da.Fill(dt); bs.DataSource = dt; if(dt.Rows.Count != 0) { qDesigner.dgvFilters.AutoGenerateColumns = false; qDesigner.dgvFilters.DataSource = bs; qDesigner.dgvFilters.Columns["dgvColTable"].DataPropertyName = dt.Columns[0].ColumnName;
Can anyone help me with this issue?
Thanks
|
|
|
|
|
i am trying to show the records in labels like so:
User Name User
Alias Alias
Income Income
Gender Gender
Age Age
and then i want the buttons to control so i can hit next to show the next record
so for that i have this code
public void GetUserMatch(XmlNode usersNode, string CritBody, string CritAgeFrom, string CritAgeTo, string CritHeightFrom, string CritHeightTo)
{
XmlNodeList userNodes = usersNode.SelectNodes("Clients");
Users[] users = new Users[userNodes.Count];
MatchUsers[] matchUser = new MatchUsers[users.Length];
for (int i = 0x0; i < users.Length; i++)
{
XmlNode userNode = userNodes[i];
string userName = userNode.SelectSingleNode("Username").InnerText;
string alias = userNode.SelectSingleNode("Alias").InnerText;
string bodyType = userNode.SelectSingleNode("BodyType").InnerText;
string strheight = userNode.SelectSingleNode("Heightft").InnerText;
string displayheight = userNode.SelectSingleNode("DisplayHeight").InnerText;
string strage = userNode.SelectSingleNode("Age").InnerText;
string gender = userNode.SelectSingleNode("Gender").InnerText;
string income = userNode.SelectSingleNode("Income").InnerText;
int intHeight = Convert.ToInt32(strheight);
int intAge = Convert.ToInt32(strage);
users[i] = new Users(userName, alias, bodyType, intHeight, displayheight, intAge, gender, income);
}
MatchUsers[] matchUsers = new MatchUsers[0];
int ii = 0;
foreach (Users mUser in users)
{
string Bodytype = mUser.BodyType;
if (string.Compare(Bodytype, CritBody) == 0)
{
int intAge = Convert.ToInt32(mUser.Age);
if (intAge >= Convert.ToInt32(CritAgeFrom) & intAge <= Convert.ToInt32(CritAgeTo))
{
int intHeight = Convert.ToInt32(mUser.Height);
if (intHeight >= Convert.ToInt32(CritHeightFrom) & intHeight <= Convert.ToInt32(CritHeightTo))
{
string userName = mUser.UserName;
string alias = mUser.Alias;
string bodyType = mUser.BodyType;
string height = mUser.DisplayHeight;
string age = mUser.Age.ToString();
string gender = mUser.Gender;
string income = mUser.Income;
matchUser[ii] = new MatchUsers(userName, alias, bodyType, height, age, gender, income);
ii++;
}
}
}
}
DataSet ds = new DataSet();
DataTable dt = new DataTable("UserMatch");
ds.Tables.Add(dt);
DataColumn dc1 = new DataColumn("User Name");
DataColumn dc2 = new DataColumn("Alias");
DataColumn dc3 = new DataColumn("Body Type");
DataColumn dc4 = new DataColumn("Height");
DataColumn dc5 = new DataColumn("Age");
DataColumn dc6 = new DataColumn("Gender");
DataColumn dc7 = new DataColumn("Income");
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);
dt.Columns.Add(dc6);
dt.Columns.Add(dc7);
int iii = 0;
foreach (MatchUsers mUsers in matchUser)
{
DataRow dr = dt.NewRow();
if (mUsers != null)
{
dr["User Name"] = mUsers.UserName;
dr["Alias"] = mUsers.Alias;
dr["Body Type"] = mUsers.BodyType;
dr["Height"] = mUsers.Height;
dr["Age"] = mUsers.Age;
dr["Gender"] = mUsers.Gender;
dr["Income"] = mUsers.Income;
dt.Rows.Add(dr);
iii++;
}
}
this.UserBindingSource.DataSource = ds;
int asdf = this.UserBindingSource.Count;
this.lblMatchUserName.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.User Name",
true));
this.lblMatchUserAlias.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.Alias",
true));
this.lblMatchUserBody.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.Body Type",
true));
this.lblMatchUserHeight.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.Height",
true));
this.lblMatchUserAge.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.Age",
true));
this.lblMatchUserGender.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.Gender",
true));
this.lblMatchUserIncome.DataBindings.Add(
new Binding("Text",
this.UserBindingSource,
"UserMatch.Income",
true));
}
Now the problem im having is that when i check the count of binding source it is equal to one.. and the code i have to go to the next record is like so:
private void button1_Click(object sender, EventArgs e)
{
if (this.UserBindingSource.Position + 1 < this.UserBindingSource.Count)
{
this.UserBindingSource.MoveNext();
this.fnDisplayPosition();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.UserBindingSource.MovePrevious();
this.fnDisplayPosition();
}
private void fnDisplayPosition()
{
this.lblPostion.Text = this.UserBindingSource.Position +
1 + " of " + this.UserBindingSource.Count;
}
so the part
if (this.UserBindingSource.Position + 1 < this.UserBindingSource.Count) is never true because binding source is always one. please tell me what am i doing wrong and how to solve this. thank you
|
|
|
|
|
Firstly are you sure that the GetUserMatch method is retrieving more than one record?
Secondly it strikes me that it might be easier to read the data directly into the DataSet and apply bindings through that.
Lastly and this is purely out of curiosity. Reading your code I noticed this:
for (int i = 0x0; i < users.Length; i++)<br />
Is there a particular reason that you are initializing i in hex? Can't think why not, just never seen it before.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
to answer the first yes i did check the getusermatch it is retreiving two records.. as it falls under it.. and second and third.. i really don't know alot about it but it is what i did after looking around in couple of websites and on msdn.
|
|
|
|
|
If you haven't already done so, take a look at the DataSet.ReadXML method.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
I am absolutely new to .NET and XML programming.
My query is regarding interprocess communication.
Assume that I have two executables written in .NET and I wish to pass some XML information between them.
I need to consider 2 cases: 1. These 2 executables reside on the same machine 2. They reside on different machines.
What methods/protocols are available to do this kind of communication?
Any pointers would be really helpful.
Thanks !
- NB
|
|
|
|
|
You have lots of options:
Remoting[^]
MSMQ[^]
Sockets[^]
All of those can send data between processes across machines and if you can do that then you can also send data between processes on the same machine.
|
|
|
|
|
Thanks !
Do you think SOAP is also an option for this scenario?
|
|
|
|
|
The only time that I've encountered SOAP is when dealing with web services. If all you need to do is pass data between 2 processes then standing up a web server just to use SOAP would be a lot of overkill.
|
|
|
|
|
|
Hey guys
I've been battling to get a response from a server using TcpClient. Now finally after 3 days of problems due to the learning curve I'm getting responses from the server
Here is the code at the moment.
private void ReceiveMessages()
{
try
{
srReceiver = new StreamReader(tcpServer.GetStream());
string result = string.Empty;
while (Connected)
{
char CurrentChar = (char)srReceiver.Read();
if (CurrentChar == RecordTerminator)
{
result += "[Record Terminator]";
}
else if (CurrentChar == FieldTerminator)
{
result += "[Field Terminator]";
}
else if (CurrentChar == PacketTerminator)
{
result += "[Packet Terminator]";
}
else
{
result += CurrentChar.ToString();
}
if (#########)
{
this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { result });
result = string.Empty;
}
}
}
catch (Exception ex)
{
this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { ex.Message });
}
}
Now one of the weirdness's I came across is that if I try StreamReader.ReadLine() I get empty strings as response.
If I use StreamReader.Read() I get the correct response, one character at a time.
Obviously i cant use the CallBack for every character received as this is way to slow, so what I'd like is to only send the use the callback after all the data has been read. But how do i know when its finished? IE what condition do i need to set instead of the #########? Cause if StreamReader.Read() is called and there is no data, it waits for some.
PS, I cant use the packet terminator as this is not always sent at the end of every packet response
Any ideas?
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
|
Just tried it.
It seems that its returning the size of the buffer array instead of 0 for EndOfStream or 1 for there's still data
If char[] Buffer = new char[12];
then Stream.Read(Buffer, 0, Buffer.Length); returns 12
bummer
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Hi Harvey,
reading one page of documentation on StreamReader class one can discover it has some 17 methods, and 3 properties one of them being called EndOfStream. I suggest you look into it.
On the other hand, StreamReader.Read returns an int, not a char, which you discovered since you had to add a cast to make it work. The reason for the int is documented as well.
Furthermore there is non-blocking Peek() method that might be useful.
One final remark: yours will not be the first TCP client; why don't you look at some of the CP articles about the subject?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi
how can I resive and get binary file ?
I need to build function that convert txt file into binary file and send as bits ??
and to build function that can resive those bits and convert to txt file
is it posible ? and how ?
thank's in advance
|
|
|
|
|
Hi,
once more you get 1-voted as you fail to provide sufficient data for anyone to provide a useful answer.
the quality and detail of your question reflects on the effectiveness of the help you are likely to get
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Took me 6 minutes to get that resive = receive
|
|
|
|
|
EliottA wrote: Took me 6 minutes ...
You shouldn't spend more than 6 seconds on any post that fails to even attempt at explaining what it is about.
His message is already in binary.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Presumably via sockets.
Search for "File Transfer Protocol" to read about that protocol.
Then search for a library that implements it. You will need a client, server or both depending on exactly what you are doing.
|
|
|
|