|
Thanks Steven for the recommendations, I also wasn’t aware of NHibernate, I will have a look at it. Cheers, Jared
|
|
|
|
|
Is is possible through, and I assume this would be using Platform Invoke, to create a hwnd without creating a Windows.Forms.Form?
Would i have to register a class and create a windows without showing it through windows api or is there some way just to obtain or register a unique hwnd without making a window.
Thank you very much!
|
|
|
|
|
To get an HWND (an IntPtr in .NET) for an existing Window, P/Invoke FindWindow[^].
If you want to create a Window without instantiation a Form *, you can P/Invoke CreateWindow or, preferably, the CreateWindowEx[^] API, which you can read about in the MSDN Library[^].
* Keep in mind that any control or form you create is a window. Each is tied to an HWND (via the Control.Handle property that every control - including the Form class - inherits), just like with native code. Even Java AWT and Swing classes are ultimately tied to an HWND , though through the JVM.
Also, just instantiating a Control derivative doesn't create the window. The control must be set to visible so that the window is actually created and the Control class derivative is tied to the new HWND . This is reflected by the OnHandleCreated event handler and the HandleCreated event.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thats what I though. I just didn't want to use any existing hwnds as i am writing a notify icon tray things and i dont want to tie it in with windows, so that it could be created in a console program for exaple (for whatever reason you would want to do that in the first place really beats me though).
|
|
|
|
|
That's where the NativeWindow class comes in handy, which you can attach to an existing window (including those windows in managed coding using their Control.Handle property).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The dedicated server doesn't send out emails.
I always got this msg:
The server rejected one or more recipient addresses. The server response was: 553 sorry, that domain isn't in my list of allowed rcpthosts
The email sending out code works very well on local servers, why it doesn't work on dedicated server?
I tried to change smtpserver to "localhost", it didn't work.
Can anybody help me?
Thanks a lot!!
|
|
|
|
|
You need to set up your SMTP server - if running under ASP.NET - to either forward emails for other domains or a whole slew of other problems. This is not the forum for that, however. Your problem is not with C#, but with understanding and setting up an SMTP server.
The SmtpMail class - as I've discussed previously if you would've clicked "Search comments" above this forum to search first before asking - uses the CDO client libraries, or the Virtual SMTP Service or Microsoft Exchange if installed. For ASP.NET web applications, this must be one of the latter implementations of CDO, which is a COM library that the SmtpMail class encapsulates.
You should ask about configuring the Virtual SMTP Server (since the client CDO library would probably not cause such as issue) in the Operating Systems / SysAdmin[^] forum here on Code Project.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You are right, that's server's problem.
Thank you so much!
|
|
|
|
|
Hi all,
Sorry in advance if the C# forum is the wrong place for this question, but none of the others looked quite right either...
I am trying to implement asymmetrical encryption on a web service using WSE 2.0. The example the MS includes in the Quick Start Examples that come with WSE works just fine, but I am trying to switch from the x509 cert that they provide to one that I created with makecert. Trouble is: I keep getting an error message saying that the key is bad when WSE 2.0 attempts the encryption.
My certs have private keys and the users under which both the client and server are running have full control over the directories that contain the private key files...
Has anyone managed to get this to work? Can you tell me what command line arguements you passed to makecert? Any guidance appreciated.
Thanks,
Bill
|
|
|
|
|
Bill Dean wrote:
I keep getting an error message saying that the key is bad when WSE 2.0 attempts the encryption.
Please be specific: what is the exception type and message? What are you doing in code when the exception is thrown?
Without this information, I can only guess that you're having one of three problems:- The X.509 certificate is not signed with the necessary OIDs that identify the certificate for client and/or server authentication.
- Since you made this certificate yourself, you most likely used a self-signing certificate authority (CA). You must add the CA to the trusted certificate store for the machine.
- The ceritifcate is not accessible because you've stored the private key into another user's ceritifcate store (like your local user's or the administrative store), or because the ASPNET user accountcannot access private keys by default and you're not impersonating another user (or running ASP.NET under a different user context).
I'm going to assume that since you have WSE 2.0 installed you have the Help 2 topics installed as well, so please read ms-help://MS.WSE20.1033/wse/html/34caf185-5484-42b3-98ea-3f17f3fc1f16.htm[^] and follow the links for more information.
If you post the specific exception type and message - as well as any other relevent data or code - we may be able to provide a better answer.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks Heath,
I should know better than to post such a detail-bare question. My bad.
My client application is a .net web application, running on the same machine that the web service runs on: a win2kpro development machine. I am trying to: 1) sign the request from the client with an x509 cert. 2) sign the response with an x509 cert, and 3) encrypt the response with an x509 cert.
1) and 2) are no problem. But when I add the code for 3) I get this exception:
System.Web.Services.Protocols.SoapHeaderException: Server unavailable, please try later ---> System.ComponentModel.Win32Exception: Bad Key at Microsoft.Web.Services2.Security.Cryptography.RSACryptoServiceProvider.Encrypt(Byte[] plaintext, Boolean useOAEP) at Microsoft.Web.Services2.Security.Cryptography.RSA15KeyExchangeFormatter.EncryptKey(Byte[] plainKey) at Microsoft.Web.Services2.Security.EncryptedKey.Encrypt() at Microsoft.Web.Services2.Security.EncryptedKey.GetXml(XmlDocument document) at Microsoft.Web.Services2.Security.Security.SerializeXml(SoapEnvelope document) at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessHeader(Security security, SoapEnvelope envelope) at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessMessage(SoapEnvelope envelope) at Microsoft.Web.Services2.Pipeline.ProcessOutputMessage(SoapEnvelope envelope) at Microsoft.Web.Services2.WebServicesExtension.AfterSerializeServer(SoapServerMessage message) --- End of inner exception stack trace ---
This exception is reported by the client and occurs sometime after the return in the web method is called.
The stack trace is:
SoapHeaderException: System.Web.Services.Protocols.SoapHeaderException: Server unavailable, please try later ---> System.ComponentModel.Win32Exception: Bad Key
at Microsoft.Web.Services2.Security.Cryptography.RSACryptoServiceProvider.Encrypt(Byte[] plaintext, Boolean useOAEP)
at Microsoft.Web.Services2.Security.Cryptography.RSA15KeyExchangeFormatter.EncryptKey(Byte[] plainKey)
at Microsoft.Web.Services2.Security.EncryptedKey.Encrypt()
at Microsoft.Web.Services2.Security.EncryptedKey.GetXml(XmlDocument document)
at Microsoft.Web.Services2.Security.Security.SerializeXml(SoapEnvelope document)
at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessHeader(Security security, SoapEnvelope envelope)
at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessMessage(SoapEnvelope envelope)
at Microsoft.Web.Services2.Pipeline.ProcessOutputMessage(SoapEnvelope envelope)
at Microsoft.Web.Services2.WebServicesExtension.AfterSerializeServer(SoapServerMessage message)
--- End of inner exception stack trace ---]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
SecureServiceLib.RestekSecureServiceClient2.Invoke(String methodName, Object[] parameters) in c:\projects\securewebservice\secureservicesolution\secureservicelib\clsresteksecureserviceclient2.cs:26
WSE2Client.localhost.Service2.HelloWorld() in c:\inetpub\wwwroot\WSE2Client\Web References\localhost\Reference.cs:45
WSE2Client.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\wse2client\webform1.aspx.cs:24
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
The code that adds the encryption is:
protected virtual void AddSignAndEncryptInformation()
{
_addResponseEncryption();
_addResponseSignature();
}
private void _addResponseEncryption()
{
SoapContext responseContext = ResponseSoapContext.Current;
X509SecurityToken e =this.GetResponseEncryptingSecurtyToken ();
responseContext.Security.Tokens.Add (e);
responseContext.Security.Elements.Add (new EncryptedData (e));
}
protected virtual X509SecurityToken GetResponseEncryptingSecurtyToken()
{
X509SecurityToken securityToken = null;
X509CertificateStore store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
bool open = store.OpenRead();
try
{
byte[] certHash=this.GetHash ("RestekClient");
X509CertificateCollection certs =store.FindCertificateByHash (certHash);
X509Certificate cert =
((X509Certificate) certs[0]);
if (cert != null)
{
securityToken = new X509SecurityToken(cert);
}
}
finally
{
if (store != null)
store.Close();
}
bool b= securityToken.Certificate.SupportsDataEncryption ;
if (b)
return securityToken;
throw new Exception ("Cert does not support data encryption");
}
private byte[] GetHash(string KeyName)
{
byte[] b=null;
if (KeyName=="RestekClient")
b=new byte[] {0xee, 0x2b, 0xba, 0xb4, 0xeb, 0x6d, 0xff, 0x1e, 0xf2, 0xc4, 0x70, 0xf9, 0x10, 0xa5, 0xfd, 0xf4, 0x03, 0xd8, 0xfb, 0xaf};
if (KeyName=="RestekServer")
b=new byte[] {0xab, 0xaf, 0xe2, 0x9d, 0xa2, 0x0a, 0xda, 0xd1, 0x02, 0x0d, 0xee, 0x50, 0xf1, 0xf1, 0xb5, 0xc1, 0x22, 0x4c, 0x1d, 0xe3};
if (KeyName=="WSEQuickStartServer")
b=new byte[] {0x87, 0xd9, 0x2c, 0xca, 0xb7, 0x14, 0xc3, 0x0d, 0xb0, 0xe0, 0xba, 0xe6, 0xb9, 0xb0, 0xb6, 0x5b, 0x5d, 0x6d, 0xf7, 0xcf};
return(b);
}
and the trivial webmethod I am using to test all this stuff is:
[WebMethod]
public string HelloWorld()
{
this.AssureCredentialsValid ();
this.AddSignAndEncryptInformation ();
return ("Hello World");
}
According to the WSE2 Cert tool, the ASPNET user has full control over the private key file for the RestekClient cert. Yes, the cert is self-signed. Any further guidance anyone can provide will be greatly appreciated.
Thanks again
Bill
|
|
|
|
|
For starters, make sure the CA that signed your X.509 certificate is installed into the trusted CA store of your machine.
If that fails I can look into it more. The certificate must be trusted, however, which is one likely cause of "Bad key" (it could also be that you didn't enable the right attributes for the key to sign and encrypt data, so be sure to check that as well).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the follow-up Heath.
The cert is self-signed, so I am assuming that I need to add the certificate itself to my trusted CA store...right? Assuming this is correct, I exported the cert from Local Computer \ Personal and then imported it into Local Machine \ Trusted Root Authority...but the problem remains.
How can I tell for sure if it is trusted?
How can I tell if I have enable[ed] the right attributes for the key to sign and encrypt data?
Thank for entertaining my questions...I've been through the WSE2.0 docs 1/2 a dozen times and cannot find the answer, so I am a little at whit's end. Any other good sources of documentation?
Bill
|
|
|
|
|
Actually, you must add the CA (the CA was self-signed, and then used to sign your certificate - at least that's what you were supposed to do) to the trusted CA store. If you don't, then the security implementation won't trust your certificate you use to sign and encrypt data because it doesn't trust what signed it.
Read a very old tutorial of mine about certificates and using OpenSSL at http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=209[^]. It may provide some limited insight.
You should not be using your self-signed CA for signing and encrypting data. You use that to sign certificates for certain purposes, and the CA must be set up to be able to sign with those privileges. My tutorial covers that, and there's a lot of information on the web about X.509, which is beyond the scope of this article.
You can look at the certificate in Windows to see what it is signed to do. Just double-click the file assuming it's in a format that Windows understands (like an X.509 DER file - a binary DER-encoded file). There usually have .pfx extensions (but of course the extension is meaningless if the file format isn't correct).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
I'm not a new programmer, but this one's got me stymied; hopefully it's a fairly trivial problem.
I'm using a socket connection to receive communication from a server. Normally, the entire message is received before the program moves on with its next instructions. However, at times when the processor is particularly busy the program seems to progress with its instructions without having received the entire communication. In other words, it seems to clean out the buffer, which due to the computer's business is holding only the first packet at this point, then move on without waiting for the buffer to fill with the next packet.
Is there a way to stop the program until it has been told that the entire communication has been received? Or a way to iteratively receive the packets until the program is told the communication is finished?
Here's my code:
<br />
IPHostEntry IPAdd = Dns.Resolve("servername.com");<br />
IPEndPoint IPEP = new IPEndPoint(IPAdd.AddressList[0], 2628);<br />
Socket s = new Socket(IPEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);<br />
string str = "Message"<br />
Byte[] Receiver = new Byte[50000];<br />
s.Connect(IPEP);<br />
Int32 bytes = s.Receive(Receiver, Receiver.Length, 0);<br />
Byte[] Sender = System.Text.Encoding.ASCII.GetBytes(str);<br />
s.Send(Sender, Sender.Length, 0);<br />
bytes = s.Receive(Receiver, Receiver.Length, 0);<br />
strResponse = System.Text.Encoding.ASCII.GetString(Receiver, 0, bytes);<br />
...Furthur code
Thanks for your help!
|
|
|
|
|
Take a look at some of the options from the SocketOptionName enumeration. This is used in conjunection with the SocketOptionLevel to set socket options using the Socket.SetSocketOption method. Not allowing your packets to be fragmented might be one option.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Interesting. I'll take a look.
Thanks.
|
|
|
|
|
I am working on a project the involves transferring data from a bar code scanner. The scanner runs PC-DOS and has a command line transfer utility that uses Xmodem. I have written an application that shells out and uses the same CLI utility to receive the file. This works, but I would like to impliment my own Xmodem protocol into my application to have more control over what is happening (and just to learn).
So far I haven't found any *free* examples of an Xmodem implimentation using C#. I have found several products that I can purchase, but this isn't what I had in mind.
I have found the specification for the Xmodem protocol and it's reads as being fairly straight forward. I'm curious to if anyone else has written the own implimentation, or if I'm overlooking why this shouldn't be too difficult.
|
|
|
|
|
therealmccoy wrote:
So far I haven't found any *free* examples of an Xmodem implimentation using C#. I have found several products that I can purchase, but this isn't what I had in mind.
If you can't find anything free using google or some other web search and you can't find anything by clicking "Search comments" in this forum (since it isn't indexed by google and the other major search engines...yet), then anything free doesn't exist.
You'll either have to implement your own xmodem APIs or purchase one of the libraries you've found. I'm sure the developers have spent a lot of time and planning and deserve what they get. You would like to get paid for your projects, wouldn't you?
Besides, with a paid product you can expect support. With free ones you're at the author's whim.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
You'll either have to implement your own xmodem APIs or purchase one of the libraries you've found. I'm sure the developers have spent a lot of time and planning and deserve what they get. You would like to get paid for your projects, wouldn't you?
In order to get paid for any of my projects I will need to learn a lot more. With that in mind I guess I will be implimenting my own interface (ohhh.. what a challenge). During the course of this project I'm sure I'll have more questions, but when I'm done this API it will be released into the public domain, much like the original Xmodem specification was.
For others searching this forum and looking for information on an Xmodem implimentation (as well as the total lack of any type of serial support in .NET) check the following site:
http://ourworld.compuserve.com/homepages/richard_grier/xmcomm.htm[^]
|
|
|
|
|
There should be in .NET 2.0, codename "Whidbey". See http://msdn2.microsoft.com/library/System.IO.Ports[^] for details.
Because "Whidbey" is currently in beta, there is no gaurantee that what you read now will be there in the release, but do have comfort in the knowledge that serial support in the BCL is something that has been requested by the community for a long time.
If you need to or want to implement your Xmodem implementation for .NET 1.0 and 1.1, I recommend downloading[^] the .NET Framework 2.0 runtime and SDK and using ildasm.exe - the IL Disassembler - from the SDK's Bin directory to examine how the System.IO.Ports namespace classes work with the Win32 APIs. You can also use .NET Reflector[^] to decompile (and disassembler) the assemblies to get tips for your own implementation.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am trying to return a string(char*) from a c++ dll and the string i return comes out blank. can anyone help me on this.
Vinayak D. Labade
|
|
|
|
|
Maybe, but since you didn't provide any required information - like the C# method and C++ function signatures - it's impossible to help you.
One thing I can tell you, however, is that keep in mind a string (System.String ) is already a reference type, so unless you see char** don't use ref or out with the parameter, despite any [in] or [out] comments you may see in the API documentation.
If you paste your C++ signature, I can tell you what the C# signature should be. Be explicit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thnaks ...
here is the code snippet taht I am using.
C# code
-------------------------------------------------
public class newtestdll
{
[DllImport("C:\\DLLDEV\\qw\\debug\\qw.DLL", EntryPoint="ReportVersion", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern string ReportVersion(string str);
}
-------------------------------------------------
str = newtestdll.ReportVersion(string);//function call
--------------------------------------------------
**************************************************
--------------------------------------------------
C++ definition
---------------------------------------------------
__declspec(dllexport) char* CQwApp::ReportVersion(char* a)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
a = "return String";
return a;
}
---------------------------------------------------
I even tried using StringBuilder but am not able to modify the StringBuilder properly.
Vinayak D. Labade
|
|
|
|
|