|
This... is a long road with many a winding turn... took me quite some time to get everything working correctly.
You fail to specify whether your C#-app is an ASP.NET web service client or a console/winforms web service client. I'll presume it's the latter as that's remarkably easier.
At either length it's easiest to use Microsoft WSE 1.0 enhancements[^] to fetch the certificate from the certificate store.
By default it is presumed that your client certificate is in the personal store of the current user (e.g. the one that is executing the application). If this is ASP.NET then as the user doesn't have a login profile the user doesn't have a personal store folder either and you need to carefully import the certificate to the personal store of the local machine.
The following code will get the private certificate from the depths of the certificate store:
<br />
byte[] certhash = { 50, 49, 239, 183, 249, 60, 36, 134, 129, 159, 39, <br />
226, 197, 70, 76, 1, 147, 237, 43, 217 };<br />
<br />
X509CertificateStore store = X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore);<br />
store.Open();<br />
X509CertificateCollection certs = store.FindCertificateByHash(certhash);<br />
store.Close();<br />
X509Certificate cert = certs[0];<br />
There are other ways to find a certificate than by using its hash value, but you can refer to the WSE 1.0 documentation for these.
Now, to add the certificate to the service call let's presume your web service object is Service1 then you add it fairly simply using:
<br />
Service1.ClientCertificates.Add(cert);<br />
It doesn't seem so daunting when you look at it like this, but it can take a lot of time to figure out given the.... usefulness.... of most code examples around. I think that's all it takes, good luck fighting the certificate mmc snap-in.
Hope this helps.
--
Henrik Stuart (http://www.unprompted.com/hstuart/[^])
|
|
|
|
|
I've got a webservice that appears to be working. What I mean is that when I execute it in Vis Studio and bring up the web interface, it works just fine. However, when I try to use it in a program using SOAP I get this:
"An unhandled exception of type 'System.Net.WebException' occurred in system.web.services.dll
Additional information: The request failed with HTTP status 401: Access Denied."
I'm almost sure it's something with the Web Server (IIS), but I'm not sure what I've done that is restricting this access and how I can fix it. Any ideas?
Thanks for your help!
|
|
|
|
|
You need to check the access permissions on the directory in IIS and make sure that anonymous authentication is enabled for that virtual directory; otherwise, you must provide credentials (NTLM, Kerberos, BASIC and digest are supported by the FCL) using the Credentials property on your Web Service proxy that is inheritted by the WebClientProtocol class. See the documentation for the WebClientProtocol in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
OK here is my dilemma, I have created a windows form (loginPage) that works fine. Now once they have entered their login ID & password I would like them to continue to the main menu form that was also created by the Visual Studio form Designer. However I cannot figure out how to switch control from the loginPage to the mainMenu form. The code is Application.Run(new loginPage()); for the loginPage. I can use the same statement with the main menu and it runs fine too, however I cannot figure out how to link the two so that only after the loginPage completes it runs the main menu.
Also the Main() function is in the .cs file for the loginPage form. Does this matter or should I create a controlling .cs program outside of the form to have Main() in it? Any preferences or coding style?
Im an old (10 yrs ago) C programmer and just getting back into VS programming.
Thanks in Advance,
Daniel Stagg
|
|
|
|
|
Simple enough... Your using the wrong page for Startup. Use the frmMain form for startup and have it call the login form. This will also give you the flexibility of putting code in your forms that, if necessary, can check to see if the user is logged in and, if not, call the login form from anywhere in your app.
RageInTheMachine9532
|
|
|
|
|
Ok. So how exactly do I call the loginPage from the mainForm?
Basically I start the project with the mainForm and it gets Main() and the Application.Run() but where in the codeset do I call and how do I call another form?
Thanks.
|
|
|
|
|
This will create a new login form object (assuming you called it 'frmLogin') and show the form as a modal dialog with your main form as it's owner (referref to as 'this').
frmLogin LoginForm = new frmLogin();
LoginForm.ShowDialog(this);
RageInTheMachine9532
|
|
|
|
|
Hi,
i have next class :
public class abc
{
public string campo 1;
public string campo 2;
public Socket CltSckt;
public NetWorkStream NS;
}
After of initialize the class and stored the data for each variable, I wish to send or store in a Queue :
public int EscribeCola(string SrvName, string QueueName, abc Msg_Devices)
{
try
{
MessageQueue msgq = new MessageQueue();
msgq.Formatter = new XmlMessageFormatter(new Type[] {typeof(string)});
System.Messaging.Message msg = new System.Messaging.Message();
msgq.Path = (SrvName + QueueName);
//
// coloco el mensaje en la cola
lock(this)
{
msgq.Send(Mensaje_Devices);
}
msgq.Dispose();
return 0;
}
catch (Exception ex)
{
acc_evento.ReportaEvento(PROCESO_ORIGEN,Param_Eventos.PROBLEMA_WRITE_QUEUE, QueueName + " " +
ex.Message + " " + ex.InnerException.Message);
return -1;
}
}
In the moment of "send", present a runtime error :
"There was an error refecting 'Msg_Devices'"
"System.net.sockets.socket"
"Cannot be serialized because it does not have a default constructor".
May you help me?
What have I do?
Grettings
|
|
|
|
|
It's indicating that you can't serialize the Socket object, looks like to me; not only does it not have a default constructor, but it doesn't implement the ISerializable interface isn't marked with the SerializableAttribute attribute. What would be the value in serializing a socket, anyway? You can mark it with the [NonSerialized] attribute to avoid this problem.
Regards,
Jeff Varszegi
EEEP! An Extensible Expression Evaluation Package
|
|
|
|
|
To note, something doesn't have to implement ISerializable to be serializable - only to be attributed with the SerializableAttribute (not inheritted with the formatters provided in the FCL, as it should be). The interface is just to customize how an object is serialized. You're still right about the Socket class not being serializable, though. I mean, that's just silly!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Whoops, right you are. My Java undies are showing-- in Java the Serializable interface is just a marker interface, with Externalizable the one you implement to provide your own serialization routine. I get mixed up sometimes because some things are so similar in Java and .NET, and I still have to use both at work. I'm getting used to rapidly switching between naming and casing conventions, but the APIs still trip me up occasionally. Thanks for the correction.
Regards,
Jeff Varszegi
EEEP! An Extensible Expression Evaluation Package
|
|
|
|
|
I tried to put [NonSerialized] the class, but show me a compilation error.
Please, may you send me an example?
|
|
|
|
|
Don't put it on the class, just on the fields you don't want to serialize, like so:
<br />
public class abc<br />
{<br />
public string campo 1;<br />
public string campo 2;<br />
<br />
[NonSerialized]<br />
public Socket CltSckt; <br />
<br />
public NetWorkStream NS;<br />
}<br />
Try that and get back to me.
-Jeff
here, bloggy bloggy
|
|
|
|
|
I have written an add-in for Outlook which adds a button to the toolbar.
It works great and now I'm trying to tweak it. I cannot for the life of me figure out how to set the icon next to the text. I've tried several suggestions I've seen on the net to no avail.
Keep in mind that there is no form for the plug-in that is loaded until AFTER you press the button.
Note: The project is actually written in VB. Why in the world would I post in the C# forum? Because all the good people are now using C#. If you don't know the VB equivalent code, no big deal I can read C# well enough.
Also, what distribution files need to be included (other than the 1.1 framework)? It installs great on my two machines running power point 2003 and power point 2000. However, both machiens have the development environment already on them. I sent my manager the .msi and he installed and says the button is not there. So I'm guessing some dependancy is missing.
--Tony Archer
"I can build it good, fast and cheap. Pick any two."
|
|
|
|
|
You have to deploy the interop assemblies too, like Microsoft.Office.Interop.Outlook.dll. These need to either be installed into the Global Assembly Cache (GAC) or into the installation directory of your application (or in a sub-directory configured as a probing path).
It doesn't matter if your form is loaded or not - your add-in is still loaded otherwise you'd see no command button at all. Also, if you're using Office 2003 Smart Documents and its interop assemblies, you MUST add a code-group to the machine policy that points to your assembly, even if running under the local machine. Office 2003 includes a CLR host that works differently than the executable loader in Windows.
Finally, there's plenty of information about Office solutions development in MSDN, such as Custom Button Faces in a Managed Code Add-in for the Microsoft Office System[^]. The same should work for older interop assemblies that work with older versions of Office which almost always work completely with newer versions of Office (it's all about versioning interfaces in COM).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath, You absolutely ROCK!
It was actually the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Office.dll
that was missing. I sent it to my boss, he put it into the install dir for the project and POOF everything worked.
Guess I have to manually set copy local to true. I would have thought that VS would recognize if something is not a standard Framework file (as VB6 does with com components) Oh well, that won't happen to me again.
Reading that article you linked me to now. Looks promising. Thanks!
--Tony Archer
"I can build it good, fast and cheap. Pick any two."
|
|
|
|
|
Files like that should actually be installed into the Global Assembly Cache (GAC), though, since they are common to many applications (potentially). The GAC also provides versioning support if a new one is ever installed, so that your application will continue to use the older version (since the new one isn't just copied over it - known as DLL hell) unless you used a publisher policy or assemblyBinding section in the .config file.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an XmlDocument object that I've constructed in memory.
I'd now like to display the contents in a System.Windows.Forms.TextBox.
What is the best practise for converting the XmlDocument to a string so that it can be displayed in a TextBox with the whitespace formatting intact?
Michael
CP Blog [^]
|
|
|
|
|
I'd use doc.Save(StringWriter), followed by Textbox1.Text = StringWriter.ToString()
(don't forget to call Dispose on the StringWriter).
Due to technical difficulties my previous signature, "I see dumb people" will be off until further notice. Too many people were thinking I was talking about them...
|
|
|
|
|
Does anyone know how to convert Unix time (seconds since Jan 1, 1970)
to a C# DateTime object??
TIA,
Matt
|
|
|
|
|
DateTime represents the time since 00:00:00 Jan. 01, 0001 AD. Do the math.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Do the math.
1 second
2 seconds
3 seconds
4 seconds
5 seconds
6 seconds
7 seconds
8 seconds
9 seconds
10 seconds
Damn I ran out of fingers, where was I again...?
|
|
|
|
|
Hi, im making a custom control inherited from System.Windows.ListView. I would like to add a filters to its columns and others features to work with datatables y detalis view.
Its possible to add a textbox control to an columnheader or to and items of lisview?
Can I only had fiters using System.Runtime.InteropServices messages overrating winproc way?
How can I capture keypress, keyup, or keydow of filters of lisview (System.Runtime.InteropServices messages overrating winproc (IE))
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
You're writing a custom ListView and you have no ideas about any of this stuff?! You should read some of the articles on this site, such as the ListViewFilter Control for .NET[^].
The ListView already has events for the keyboard. If you're looking for information on all the messages, see the Platform SDK in the Common Controls section for the List-View common control reference.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you, in this moment i have my custom control in this way (using your tips) adding at run time textbox for each colum in listview and works fine, usinf the keyup event (enter key) of textbox for make the filter. But this has a problem when the colums are bigger than the lisviww.width or resize the column.width. For that I try changing the size of textbox at the time when the column do it and work fine. Or making the colums fixed.
Then Found ListViewFilter a see the columns whit nice filters, but coulnt find to capture the event keyup of these filters only texchange an click the button of the filter.
In other hand i would like no use the interop with windows dll because i don want to take mi code with only .net and in the future use it in diferent plataforms.
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|