|
James T. Johnson wrote:
ASP.NET forums
Nice link .
|
|
|
|
|
I am using Datagrid. In some columns I used comboboxxes and in rest textboxes by handling events . That meant I am placing the combobox ot text box on mouse click to appropriate cell.Here I want to avoid sorting.But even if I set allowsort property to false if not works.What can be the possible problem ?
VikramVS
|
|
|
|
|
Hey all - I'm trying to get an RSS feed using the System.Net.WebRequest class:
<br />
<br />
WebRequest requ = WebRequest.Create(feed);<br />
Stream instream;<br />
WebResponse result = requ.GetResponse();<br />
instream = result.GetResponseStream();<br />
StreamReader reader = new StreamReader(instream);<br />
String code="";<br />
while(code != null){
code+=reader.ReadLine();<br />
}<br />
Unfortunately, it is hanging in my loop that retrieves all the text from the URL. Is there a better way to read all the text out of a feed? Also, does anyone know why it is an endless loop?
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
How is code ever going to be null if you're adding to it all the time?
You have to read into a temporary string, check for null and if it's not then add it to code. Alternatively, replace the entire loop with code = reader.ReadToEnd() .
Paul
|
|
|
|
|
As usual, I find an answer for everything I post for in moments. The StreamReader has a ReadToEnd method that can be used to get the entire contents of an InputStream.
I guess I'll leave my original post in case anyone else runs into something similar.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
ARGGH! I just saw my original mistake. Sometimes I'm such a lame programmer.
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
I've been trying to write a managed interface for IActiveDesktop so I can use it to change the desktop wallpaper from a C# program. My source as it is at the moment is shown below. When I try and use any of the methods in the IActiveDesktop interface I get exceptions being thrown, mostly System.NullReferenceException but sometimes System.ArgumentException. I suspect something is wrong with my managed interface, but I'm not sure what. I've played around with changing the marshalling, but haven't hit on the answer yet. Any help would be greatly appreciated. I know there are easier ways to change the wallpaper, but I'm determined to figure this thing out now!
Thanks
----------------------------
using System;
using System.Runtime.InteropServices;
namespace ShellTypeLib
{
// Component structures for IActiveDeskTop
[StructLayout(LayoutKind.Sequential)]
struct COMPONENT
{
uint dwSize;
uint dwID;
int iComponentType;
bool fChecked;
bool fDirty;
bool fNoScroll;
COMPPOS cpPos;
char[] wszFriendlyName;
char[] wszSource;
}
[StructLayout(LayoutKind.Sequential)]
struct COMPPOS
{
uint dwSize;
int iLeft;
int iTop;
uint dwWidth;
uint dwHeight;
int izIndex;
bool fCanResize;
bool fCanResizeX;
bool fCanResizeY;
int iPreferredLeftPercent;
int iPreferredTopPercent;
}
[StructLayout(LayoutKind.Sequential)]
struct COMPONENTSOPT
{
uint dwSize;
bool fEnableComponents;
bool fActiveDesktop;
}
[StructLayout(LayoutKind.Sequential)]
struct WALLPAPEROPT
{
uint dwSize;
uint dwStyle;
}
// Declare IActiveDesktop interface
[Guid("F490EB00-1240-11D1-9888-006097DEACF9")]
interface IActiveDesktop
{
void ApplyChanges(uint dwFlags);
void GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string pwszWallpaper, uint cchWallpaper, uint dwReserved);
void SetWallpaper(string pwszWallpaper, uint dwReserved);
void GetWallpaperOptions(ref WALLPAPEROPT pwpo,uint dwReserved);
void SetWallpaperOptions(ref WALLPAPEROPT pwpo, uint dwReserved);
void GetPattern([MarshalAs(UnmanagedType.LPWStr)] string pwszPattern, uint cchPattern, uint dwReserved);
void SetPattern([MarshalAs(UnmanagedType.LPWStr)] string pwszPattern, uint dwReserved);
void GetDesktopItemOptions(ref COMPONENTSOPT pco, uint dwReserved);
void SetDesktopItemOptions(ref COMPONENTSOPT pcomp, uint dwReserved);
void AddDesktopItem(ref COMPONENT pcomp, uint dwReserved);
void AddDesktopItemWithUI(IntPtr hwnd, ref COMPONENT pcomp, uint dwReserved);
void ModifyDesktopItem(ref COMPONENT pcomp, uint dwFlags);
void RemoveDesktopItem(ref COMPONENT pcomp, uint dwReserved);
void GetDesktopItemCount(int lpiCount, uint dwReserved);
void GetDesktopItem(int nComponent, ref COMPONENT pcomp, uint dwReserved);
void GetDesktopItemByID(uint dwID, ref COMPONENT pcomp, uint dwReserved);
void GenerateDesktopItemHtml([MarshalAs(UnmanagedType.LPWStr)] string pwszFileName, ref COMPONENT pcomp, uint dwReserved);
void AddUrl(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszSource, ref COMPONENT pcomp, uint dwFlags);
void GetDesktopItemBySource([MarshalAs(UnmanagedType.LPWStr)] string pszSource, ref COMPONENT pcomp, uint dwReserved);
}
// Declare ActiveDesktop as a COM coclass
[ComImport, Guid("75048700-EF1F-11D0-9888-006097DEACF9")]
class ActiveDesktop
{
}
}
namespace Wallpaper_test
{
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
ShellTypeLib.ActiveDesktop MyDesktop = new ShellTypeLib.ActiveDesktop();
ShellTypeLib.IActiveDesktop IDesk = (ShellTypeLib.IActiveDesktop) MyDesktop;
IDesk.SetWallpaper("Test.bmp",0);
IDesk.ApplyChanges(1);
}
}
}
|
|
|
|
|
I have randomly taken one method GetDesktopItemCount that wasn't working with your code, and got it to work thanks to slight modifications :
- declare this method as :
uint GetDesktopItemCount(out int lpiCount);
- use it :
int nbdesktops = 0;
uint hresult = IDesk.GetDesktopItemCount(out nbdesktops);
In other words, - IActiveDesktop is not a dispatch interface, so you must consume the HRESULT value in return. - out values are marshalled with the out attribute.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
With respect, that doesn't appear to be working either! I declared the GetDesktopItemCount as you did and then called in in my main program but I noticed that if I set nbdesktops to say 10 then after the function it is still 10! Also the HRESULT returned is non-zero even though no exception is thrown (it returns 0x129ADC which I don't know how to look up). Also what happened to the unit dwReserved parameter?
I declared the GetWallpaper function as:
uint SetWallpaper(string pwszWallpaper, uint dwReserved);
and it now seems to not throw an exception and even returns 0, but doesn't seem to actually do anything . I suspect that nothing will happen until I call the ApplyChanges method but that one still isn't working
|
|
|
|
|
Any luck with a solution for this problem? I would like to use the IActiveDesktop interface from a C# application as well.
I tried importing it via the Visual Studio method but I don't see the interface listed.
.:. Keno .:.
|
|
|
|
|
|
Apologies for reposting the question. I posted it first in the .NET forum. I am desperate to get an answer prompting me to post here again.
--------------------------
I created a .NET web service that was to be consumed by a .NET web application.
Now I have a problem. I made a session variable in the Web Service and stored the instance of the Web Service in a session variable in the Web application.
I have two problems
1. The session variable in the Web service is lost in subsequent calls.
2. The WebService object in the Web app session is NULL in every submit from the browser.
Have anyone implemented something like this? Is this the correct way to implement a state-ful Web Service?
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
The session management mode in the config file of ASP.NET is "inproc"
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Hi Thomas
I had exactly the same problem starting with web stuff a short while back and I was like WTF??*&^*&*%%&^(*& are my objects?
The answer is short and sweet. In ASP.NET objects are stateless, meaning the will be recreated with every pageview.
Now the fix, and I'm not really sure if this the correct way, but all u need to do is mark those two variables in question as static. They will now retain their state.
Hope this helps
|
|
|
|
|
leppie wrote:
Now the fix, and I'm not really sure if this the correct way, but all u need to do is mark those two variables in question as static.
I tried this once and could not get it to work.
I just wanted to test it out so I built a webservice that incrimented a variable by one each time it was hit.
The variable was always zero.
|
|
|
|
|
Ray Cassick wrote:
I just wanted to test it out so I built a webservice that incrimented a variable by one each time it was hit.
Are you sure it was hit hard enough, maybe a 10 pound hammer will better
Ray Cassick wrote:
The variable was always zero.
That was the problem i had, before the object was marked static. Well it solved my problem...well, I wouldnt say it looks right, but it was my first try.
CHeers
|
|
|
|
|
I found the answer:
On the line that says [WebService]
change to
[WebService(EnableSession=true)]
and it works!!!!
modified 29-Aug-18 21:01pm.
|
|
|
|
|
WOW thanx, I need all the tips I can get
I think in my case static was the right answer, as the variable needed to have application scope and was started in the application started event and shutdown in the application end event.
It seems to work but with many problems. Normal builds didnt update the assembly on the webserver, so I have to do a Re-build every time. Not sure if this is normal
Cheers
|
|
|
|
|
Now the second part of my problem remains.
The web application starts a new session every time a web method on the WebService is called, even though I have created an instance of the Web Service in the Session_Start and kept it in a Session Variable.
Very unfortunate
Any ideas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thomas George wrote:
The web application starts a new session every time a web method on the WebService is called, even though I have created an instance of the Web Service in the Session_Start and kept it in a Session Variable.
SOmething sounds funny. Remember any session variables will only be there for the duration of the session. Maybe the session gets reset somewhere . Try adding breakpoints at session start/end events and see what happens....
Good luck
|
|
|
|
|
i got the answer for this one too.
After creating the WebService object, create a cookie container for it.
Suppose you web service name is xyz.ws
so the code in Session_Start will be
xyz.ws ws1 = new xyz.ws();
ws1.CookieContainer = new System.Net.CookieContainer;
Session["ws1"] = ws1;
Now you can get the same WebService session from this Web App Session using the session variable.
Nice talking to you though. Got me thinking on a lot of things. I work here alone and I need someone to talk to about tech stuff once in a while .
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thanx Thomas
Very helpful indeed.
O BTW , I spotted this website and downloaded it, but forgot about it ... DOPE!
http://samples.gotdotnet.com/quickstart/aspplus/doc/default.aspx[^]
When I was looking at it, it looked very helpful indeed, much better than the "few" examples on MSDN.
Thomas George wrote:
Nice talking to you though. Got me thinking on a lot of things. I work here alone and I need someone to talk to about tech stuff once in a while .
Thanx again I work from home, but prefer to work alone, with some online help. Unfortunately my free GPRS connection comes to an end this month, so daytime will be a bit lonely untill ADSL becomes available in my area (local peak phone calls are probably the highest in the world (i dont even want to mention the cost per MB for GPRS once this free trial ends )).
Cheers
|
|
|
|
|
The code in the previous post is for the web application. Web service objects created in an app by default is sessionless ie, it does not store the cookies. We just create a cookie container and ,wow, it is like invoking from a browser...
modified 29-Aug-18 21:01pm.
|
|
|
|
|
So the only difference between a web app and a web service is how a session is defined?
|
|
|
|
|
When a web application becomes the client for a webservice, that has state, the web application should identify the session in every request to the web service. Normally, this does not happen because the Web application does not store cookies. But, the Web service proxy object inside the web application can store the cookie, if one is created by the user.
The web service by default does not manage states - because it is a performance overhead. So, we have to explicitly enable session support for each web method that needs it, so that the session is loaded for the particular web method call (an extra load which we ask the ASP.NET framework to do by the EnableSession=true directive).
modified 29-Aug-18 21:01pm.
|
|
|
|