|
Kant wrote:
Ex: In a GUI application, let the user input the URL of the web service and based on that can we generate the proxy?
You can always generate the proxy and compile it. But I think that the easier way would be reading the WSDL definition (after all, it's usually a really simple XML) and creating a SOAP message (another XML), then send it through HTTP. Probably you'll find some sample (not in .NET) that already does this...
I see dumb people
|
|
|
|
|
Unless you want a typed web service proxy, you could extend SoapHttpClientProtocol (which generated web service proxies do by default) and instantiate that, either providing the URL to the WSDL document in the constructor or set the Url property (inheritted from WebClientProtocol ) after instantiation. As soon as you call Discover to set up the bindings, you can use Invoke to invoke the methods you want. Invoke is protected, which is why you must extend the SoapHttpClientProtocol , but you could always expose an override as public if you wanted. You could do the same with the asynchronous protected methods (BeginInvoke and EndInvoke ).
Without knowing what the bindings are, however, this could get pretty messy. That's where the DiscoveryClientProtocol comes in, another derivative of the WebClientProtocol . From this you can get a DiscoveryDocument which you can use to discover the bindings supported by the web service.
If you want to generate typed proxies, you can use the concepts presented above to do that. As I mentioned, the proxies extend SoapHttpClientProtocol and add methods for each of the bindings through discovery and simple call the protected Invoke to call them (or the asynchronous methods to support asynchronous methods on your proxy).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thank you for the great idea.
I actually tried to extend SoapHttpClient as you said:
public class MySoapHttpClient : SoapHttpClient {
public string TestWebMethod() { this.Invoke("TestWebMethod", ...);}
}
and use it as
MySoapHttpClient obj = new MySoapHttpClient();
obj.Url ="http://localhost/WebService7/Service1.asmx";
obj.Discover();
string s = obj.TestWebMethod();
It works fine. But I cannot replace the signaure "TestWebMethod" with a generic one "Invoke(string MethodName)".
Does it mean that Binding must be reflected in the proxy ? Or there are some ways to go arround.
James
|
|
|
|
|
You can, but you must hide the protected member by using new :
public new object[] Invoke(string methodName, object[] parameters)
{
return base.Invoke(methodName, parameters);
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi
I am uploading a file, using HTTPPostedFile.
Uploads are going fine but i want to compress the posted file
(a JPEG image actually) on the fly (i.e. before storing in the database).
For example if the client computer has selected a JPEG image file of 1056 Kb, the file uploaded / saved file size is reduced to , say 200-300 kb.
Can this be accomplished?
Any help would be appreciated
Africa is a though country
--"Hello daar vir die Afrikaans sprekendes"--
|
|
|
|
|
Since JPEG images are already compressed by their very nature, you won't get to compress them any more than MAYBE 1%.
The only method you have is to reduce the actual image size, from say 1280x1024 down to 320x240 and store that. This is the only way your going to save space. Unfortunatly, you can't blow the picture back up to it original size without a severe penalty in image quality.
RageInTheMachine9532
|
|
|
|
|
JPEG is a lossy compression algorithm: if he wants to lose some image quality, he can keep the image size and further reduce the file size, with a loss on the image size (a drop to 25% image quality produces a way better result than a shrink/expand to 25% size).
I see dumb people
|
|
|
|
|
Okay. I'm sure I'm missing something really simple, but I am thus far unable to get ChooseColor (exported from comdlg32.dll) to work.
Before anyone suggests it, I know there's a ColorDialog control available. Using it is not an option, however, since the app I'm working on is for .Net CF. When calling the ChooseColor method, the runtime returns a really useful System.NotSupportedException.
My code looks like the following:
public struct CHOOSECOLOR<br />
{<br />
public int Flags;<br />
public IntPtr hInstance;<br />
public IntPtr hwndOwner;<br />
public IntPtr lCustData;<br />
public IntPtr lpCustColors;<br />
public IntPtr lpfnHook;<br />
public string lpTemplateName;<br />
public int lStructSize;<br />
public int rgbResult;<br />
}<br />
<br />
[DllImport("comdlg32.dll")]<br />
internal static extern bool ChooseColor(ref CHOOSECOLOR pChooseColor);<br />
<br />
<br />
public void ShowColorDialog(Form parent)<br />
{<br />
if(parent != null)<br />
{<br />
CHOOSECOLOR color = new CHOOSECOLOR();<br />
color.lStructSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(CHOOSECOLOR));<br />
color.hwndOwner = FindWindow(null, parent.Text);<br />
<br />
bool result = ChooseColor(ref color);<br />
}<br />
}
Any help is much appreciated.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
The .NET CF Interop marshaler is a bit quirky. So here is the code that will do exactly what you want. Notice the use of LocalAlloc and LocalFree
<br />
[StructLayoutAttribute(LayoutKind.Sequential)]<br />
private class CHOOSECOLOR: IDisposable<br />
{<br />
private int lStructSize;<br />
<br />
internal IntPtr hwndOwner;<br />
<br />
private IntPtr hInstance;<br />
<br />
internal int rgbResult;<br />
<br />
internal IntPtr lpCustColors;<br />
<br />
internal uint Flags;<br />
<br />
private int lCustData = 0;<br />
<br />
private IntPtr lpfnHook;<br />
<br />
private IntPtr lpTemplateName;<br />
<br />
<br />
public CHOOSECOLOR()<br />
{<br />
lStructSize = Marshal.SizeOf(this);<br />
hwndOwner = IntPtr.Zero;<br />
hInstance = IntPtr.Zero;<br />
rgbResult = 16777215;<br />
lpCustColors = LocalAlloc(64, 64);<br />
Flags = 0;<br />
lCustData = 0;<br />
lpfnHook = IntPtr.Zero;<br />
lpTemplateName = IntPtr.Zero;<br />
}<br />
<br />
public virtual void Dispose()<br />
{<br />
LocalFree(lpCustColors);<br />
}<br />
}<br />
<br />
<br />
[DllImport("coredll.dll")]<br />
private static extern IntPtr LocalAlloc(int flags, int size);<br />
<br />
[DllImport("coredll.dll")]<br />
private static extern int LocalFree(IntPtr addr);<br />
<br />
[DllImport("comdlg.dll")]<br />
private static extern int ChooseColor(CHOOSECOLOR pChooseColor);<br />
<br />
[DllImport("comdlg.dll")]<br />
private static extern int CommDlgExtendedError();<br />
<br />
private void ShowChooseColor(object sender, System.EventArgs e)<br />
{<br />
CHOOSECOLOR color = new CHOOSECOLOR();<br />
int result = ChooseColor(color);<br />
if (result == 0)<br />
{<br />
MessageBox.Show("CommDlgExtendedError = " + CommDlgExtendedError().ToString());<br />
}<br />
}<br />
|
|
|
|
|
Thanks a lot! I was starting to think about adding the mem allocation calls - there are murmurings about them in one or two places, but I wasn't able to find anything concrete until your posting.
Is it just me, or does CE's usage of the API seem a little like alchemy? There seems to be very very little in the way of example on line. Perhaps there are some useful books out there...
I don't come from a C(++) background, so I'm at a little bit of a disadvantage from the outset with structure conversion / API implementation, but in this case I think I had it right, and other "quirkiness" caused problems (my desktop example worked great).
One note: The import for the common dialog library should read "commdlg.dll" - two "m"s.
Thank you again.
Jared
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
I wanted to block certain Key Combinations pressed by the user from being executed by the System when my application is active.
For example in WIN 98 when any application is running, if the user presses Ctrl+Alt+Del, the Taskmanager will popup. I want to block such events from being happening when my application is active.
Such blocking is to be implemented for certain combinations of Key presses.
Exaplination with some code examples is highly appreciated since i need to implement this pretty urgently.
CHEERS
|
|
|
|
|
|
I am having some difficulty with COM Interop at the moment, and am hoping someone can help...
What happens if you have a COM Client (i.e. COM is calling an .NET assembly using a CCW) and the .NET component (with the CCW) has references to another .NET Component. Does the 'dependancy' assembly require the CCW or an RCW? or can these 2 assemblies communicate in their native tongue (i.e. .NET).
Here is a problem I am trying to solve at the moment: I have Assembly1 which has a CCW (it is a "Custom Command" that can be called by a COM application). The second Assembly (Assembly2) contains generic methods that can be called by all kinds of different "Custom Commands". This way I get decent code re-use (all the common methods are stored in Assembly2).
I will try to 'diagram' it here:
COM (Client) -> CCW -> .NET Assembly1 -> .NET Assembly2
So if .NET Assembly1 has a reference to .NET Assembly2 can they "talk to each other" using .NET, or do they need a proxy (i.e. RCW or CCW) to communicate also?
What I am asking is... is the following config required?
COM (Client) -> CCW -> .NET Assembly1 -> RCW -> .NET Assembly2
Also, what happens if Assembly2 has other dependancies (for example Oracle.DataAccess.Net) Do these also need a wrapper?
I currently have a situation where another developer is trying to use my common code (i.e. he's trying to make his own Assembly1 which references the common methods I've made in Assembly2) but he can't seem to instantiate a class in Assembly2 because he's getting a System.IO.FileLoadException when Assembly2 is referring to the Oracle.DataAccess.dll. I've checked the HRESULT in WinError.h and it is "NTE_PROVIDER_DLL_FAIL" (i.e. "DLL Failed to initialize correctly").
Not sure if this is a COM Interop problem, or related to the fact he has 2 Oracle homes (he has Oracle 7 - installed first) and Oracle 9. I'm thinking it could also be a CAS (Code Access Security) problem? (i.e. Assembly1 has CCW so it can't call/reference/instantiate a .NET assembly which refers to another .NET assembly - Oracle.DataAccess.dll)... If he runs the Assembly2 code on his machine which calls a stub.exe (written in .NET) he can use the Oracle.DataAccess.dll no problem - but when it's in .Dll form, he gets the System.IO.FileLoadException error (above).
Any suggestions or clarification would be greatly appreciated.
|
|
|
|
|
No, the dependent assembly does not need to expose a CCW. The CCW is a way of exposing a .NET component to COM clients, but the component is still a .NET component and thus uses other .NET assemblies like any other .NET application.
These assemblies must be resolvable, however. It seems that your assembly isn't being found. When you register your assembly exposing the CCW, do so with regasm /codebase MyAssembly.dll . This registers the full path to the assembly. Better yet, install all your assemblies in the Global Assembly Cache (GAC), then just register it with regasm MyAssembly.dll .
The deal with assembly resolution is that the application directory is checked first, and then if a probing section is configured in the application's .config file, those sub-directories referenced in that section are checked as well. Since your COM client may run from anywhere and use your CCW without knowledge of where the file is (the COM system deals with this information), you don't really know where to put the second, dependent assembly. This is why you put it into the GAC. After the CLR fails to find the assembly in the application directory or probing paths (and no explicit locations are mentioned in the assemblyBinding section of the .config file), it looks in the GAC. The PATH environment variable is never used, unlike native executables.
For more information about how assemblies are resolved, read How the Runtime Locates Assemblies[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Thank you for your very prompt response. I believe that it is resolving the assembly. Assembly1 (the command) is definitely being resolved. This is installed using regasm. When we step through code on his machine we can see that it is going into Assembly2. (As soon as we remove the call to a method in Oracle.DataAccess.dll the code in Assembly2 works fine). In addition, the third assembly (a ref to Oracle.DataAccess.dll - which is made in Assembly2) is an ODP.NET .dll. This is definitely registered in the GAC, and the entry in the GAC is correct. Assembly2 is not registered in the GAC, and is not using regasm /codebase.
If I look at the 'overview' for the specific error that is being thrown(i.e. System.IO.FileLoadException) it states the following:
"The exception that is thrown when a managed assembly is found but cannot be loaded."
This is what is being thrown in Assembly2 when it's referring to Oracle.DataAccess.dll. This seems to make sense to me (i.e. it's finding it) because this (Oracle.DataAccess.dll) assembly is registered in the GAC. I've read many complaints about Oracle 9 (ODP.NET) installs which refer to a problem with OraOps9.dll. Oracle.DataAccess.dll is dependant upon OraOps9.dll. A lot of people suggest to try unchecking/re-checking the "Read and Execute" permission on the Oracle Home folder for Authenticated Users. We've tried this and it doesn't seem to work.
Do you think this is perhaps due to a problem with having 2 Oracle homes? (i.e. Oracle 7 and Oracle 9)??
|
|
|
|
|
Heath,
I am reposting so I get notification (my session expired while writing the last message, so it was posted as Anonymous).
Thank you for your very prompt response. I believe that it is resolving the assembly. Assembly1 (the command) is definitely being resolved. This is installed using regasm. When we step through code on his machine we can see that it is going into Assembly2. (As soon as we remove the call to a method in Oracle.DataAccess.dll the code in Assembly2 works fine). In addition, the third assembly (a ref to Oracle.DataAccess.dll - which is made in Assembly2) is an ODP.NET .dll. This is definitely registered in the GAC, and the entry in the GAC is correct. Assembly2 is not registered in the GAC, and is not using regasm /codebase.
If I look at the 'overview' for the specific error that is being thrown(i.e. System.IO.FileLoadException) it states the following:
"The exception that is thrown when a managed assembly is found but cannot be loaded."
This is what is being thrown in Assembly2 when it's referring to Oracle.DataAccess.dll. This seems to make sense to me (i.e. it's finding it) because this (Oracle.DataAccess.dll) assembly is registered in the GAC. I've read many complaints about Oracle 9 (ODP.NET) installs which refer to a problem with OraOps9.dll. Oracle.DataAccess.dll is dependant upon OraOps9.dll. A lot of people suggest to try unchecking/re-checking the "Read and Execute" permission on the Oracle Home folder for Authenticated Users. We've tried this and it doesn't seem to work.
Do you think this is perhaps due to a problem with having 2 Oracle homes? (i.e. Oracle 7 and Oracle 9)??
|
|
|
|
|
Yes, I remember seeing that problem referenced in this forum as well. Click on "Search comments" above and see if you can find it, otherwise I know the answer was based on a link found by googling.
Still, though, you don't need to register assemblies using regasm.exe if they don't expose any CCWs, like this "Assembly2" you mentioned, but it still needs to be resolved from whatever references it, like "Assembly1". Putting it in the same directory as the CCW wouldn't work, since that's (most likely) not the application directory. Using the GAC is about the only way to go.
To note, even native applications can have myapp.exe.config files, though they probably won't use them. I've done this in my Java/.NET interop at the presentation layer article using java.exe.config in the same directory as java.exe (runtime loader). This would allow you using a assemblyBinding section to specify the location of a certain assembly.
The biggest problem with that approach is that you must know your COM clients up-front, which is practically impossible. One of the fundamental solutions that COM presents in location-independence. With this in mind, the GAC for .NET assemblies is the solution.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Greetings All,
I am using a DataGrid bound to two tables with a master-detail relationship. As expected, I may click on the expander, click on the link, then view the detail for a particular master record. My problem: some master records may have detail and some may not ... for the master records without detail, I would like for the link *not* to show. The default behavior shows the link and after the click presents null detail data. Any ideas?
Thanks,
Bitwise
|
|
|
|
|
This functionality is pretty deeply encapsulated in the DataGrid control's private members, so you really can't change it.
You could, however, use two DataGrid s that use the same data source, but the second (detail) DataGrid uses the DataRelation between two DataTable s instead of the DataSet or DataTable itself. When you click on a row in the master DataGrid , the detail DataGrid shows the related records, if any.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!.
I have problems when I use two DataReader associated with a Connection.
I can't have more than one DataReader for each connection without closing one of them?.
The code throws the follow error:
<br />
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll<br />
<br />
Additional information: There is already an open DataReader associated with this Connection which must be closed first.<br />
I need the thow DataReaders open because for each read of DataReader1 I do operation with DataReader2 in another table.
I need two or more DateReader working together. How can I fix that?.
Thank you.
Demian.
|
|
|
|
|
You must use a seperate connection for each reader.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Alternately, you could forego the DataReader s entirely and use DataAdapter s to read all the data into DataTable s up-front and then you can operate on the (now disconnected) data without worrying about the database connections at all.
...just a thought...
Bill
|
|
|
|
|
In Crystal Report,How to set line's Properties such as : Width,Supress and Left ?
I had tried like this:
"ReportDoc.ReportDefinition.ReportObjects[ ObjectName ].Width
= 1100"
but i can't works while the object is a line.
thanks
Xpelive
|
|
|
|
|
I'm puzzled in the using of Request.cookies and Response.cookies. Could you help me an easy way to understand when i need use Request.cookies and when i need use Response.cookies.... thank you very much... Any answer would be appreciate...
|
|
|
|
|
Simple explanation: Request object is used to retrieve data from client, while Response object is used to send/write data to the client. In cookies example, use Request.cookies to read the cookie collection and use Response.cookies to create/add new cookie to the collection.
|
|
|
|