|
It's not VS.NET that's causing the problem, it's your implementation of how it defines the WSDL for the Web Service. Even generic DataSet will produce a generic declaration in WSDL. And there is not such thing as a typed ArrayList - it works only with object s, unless you've extended it and declared typed parameters.
Structs, classes, DataSet s, whatever work well so long as they can be serialized correctly / the way you want. By default, Web Services use XML Serialization attributes or simply uses the public properties (not fields, and this is documented) and their names. See XML and SOAP Serialization[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sorry - my reference to a strongly-typed ArrayList was 'lazy' English. What we actually did was create a class named MyClassList that implemented IList (to give bindability to a DataGrid) and had a private ArrayList member. It then implemented all the Methods of IList by passing them on to the ArrayList except that this[]{get()} and Add() were both typed rather than returning/accepting object s.
Our problem with WebServices was that the proxy class that VS.NET builds contained its own declarations of the data classes, so you ended up with MyNamespace.MyClass and localhost.Webservice.MyClass so Method signatures didn't match and the code wouldn't compile. The solution seemed to be simply to go into the file that VS.NET built and delete the lines that declared MyClass - then everything compiled and ran fine. Are you saying that a tweak to the way VS.NET calls WSDL would solve this problem?
My real interest, though, is whether anybody else is attempting this or just sticking to using strongly-typed Datasets to do everything?
Thanks
Bernard
|
|
|
|
|
No, just declare your classes and structs properly, perhaps attributing them with the XML Serialization attributes in System.Xml.Serialization to provide greater control.
Also, why is MyClass (assuming it's the same class) in both assemblies? Your Web Service should be declared in a different assembly and doesn't need to access it's own WSDL - it's the one generating it (rather, the ASP.NET facilities are, but for your classes).
I've used many classes in Web Services and we even use them in .NET Remoting (but that's subject to different technology, though similar in concept). There's also examples included right in the .NET Framework SDK itself, as well as examples throughout the documentation for Web Service-related classes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To cut this down to the bone, I've got three projects, MyClasses , MyClient and MyWebService and let's assume that the namespaces are the same as the project names. MyClasses contains the definition for MyClass . MyClient and MyWebService both reference the MyClasses namespace. Now let's say that MyWebService has a webservice in it, MyWS.asmx that in turn has a method whose parameter is of type MyClass or, to be precise, MyClasses.MyClass .
When I add MyWS as a web reference to MyClient, VS invokes WSDL to build a proxy for MyWS for MyClient to use which includes a new definition for MyClass. So we now have a situation where MyClient is aware of MyClasses.MyClass and is calling a Method with that type as parameter but the proxy is expecting an object of type localhost.MyWebService.MyClass (or whatever). Hence the code will not compile.
The example in MSDN seems to get round this issue by only declaring the class on the proxy file but that seems to me to be a backwards way of going about things - but maybe I've misunderstood?
Anyway, is this any clearer?
The WSDL documentation seems to suggest that the correct approach is to generate the proxy class and then modify the code by hand so I still end up back at my core question of whether there is a better or worse way of passing data between the layers from a front end via a web service, then to COM+ and finally to a SQL database or is it just as good to use our own classes as to use strongly-typed Datasets?
Thanks
Bernard
|
|
|
|
|
It was clear to begin with, but you're the intent of WSDL. The WSDL file for your web service is used to generate the client proxy, including all types necessary to makes calls on your web service. This is what WSDL is for, and what helps makes web services platform- and implementation-independent. You can discover information about a web service using the ubiquitous XML format, even at runtime.
What you're trying to do is more of a .NET Remoting tactic. You don't need to have an assembly that defines your types, since the client proxy that is generated will contain them - that again is what WSDL is partly for (to describe the types used, as well as all the methods, etc.). If you do want to share the types (perhaps they have some handy methods), then simply go into the generated class file (just show hidden files in your project) and change the type to your class from the MyClasses assembly.
Again, going back to the original question of classes vs. structs vs. DataSet s - you can use anything. You can pass the intrinics (int, long, string, char, etc.) and anything else you like, even arrays like a byte[] array (commonly used for images, though DIME is much faster).
What you use is up to you and your implementation, but you can use anything. Take a look at http://www.xmethods.net[^] for a huge list of web services, most (all?) of which don't use DataSet s and just return whatever types they want, which are defined in the web service's WSDL.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think I've got it! What you're saying is that I only reference MyClasses from MyWebService and not from MyClient; MyClient then uses the classes in the file that WSDL builds.
The classes we're passing specifically don't have methods, they're just a means for carrying data so that issue doesn't arise.
I'll have an experiment with this and see where it goes.
Thanks for your help
Bernard
|
|
|
|
|
hi
i have a map of picture in rgb . i want to show it in a picture box but i can,t find any method to convert byte[](i mean map) to image.
can enybody help me.
Regards Amir jalaly
|
|
|
|
|
Set a MemoryStream from your byte array and then use Image.FromStream() method.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Hi,
I come from Delphi and I'm trying to create an object instance throught his name obtained in a component property. In Delphi I do (more less)
ObjectInstance = CreateInstance(ObjectName: String)
There is something similar in C# ?
Thanks
Pedro E. Pasamar Vidal
|
|
|
|
|
Hi,
You can use "System.Activator.CreateInstance" method.....It has around 9 overloaded methods....I normally use the one in which you give the System.Type of the class you want to instantiate, but there is also a method in whihc you specify the name of the class (as string) and the assembly name (as string) in which this class exists. This method will be helpful to you
Or you can also use one of teh overloaded method of "System.Activator.CreateInstanceFrom"...which takes name of the file of the assembly and teh name of the class
You'll then have to typecast the returned object to the type of your class
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
Hi,
I have following requirements to achieve: I have some images and I am adding them as a resource to a dll. This dll is then to be used for getting those images by the other clients.
Now to do so first I generated a .resx file which includes all these images in the xml form. Then I convernted .resx to .resource file using resgen.exe. After this I used al.exe to generate .resource.dll from .resource file using neutral culture. Once done, I implemented a .cs file which has all those public getter methods for interface for the clients. I then compiled it and attached the .resource.dll file I earlier made.
Now when I am using this dll in some client, I get a runtime error "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module."
I couldn't figure out whats wrong with it. Can some one help me out?
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
You're close. First, read Resources in Applications[^] in the .NET Framework SDK.
Satellite assemblies are different from primary assemblies, which contain modules. Satellite assemblies contain only resources and they do define a locale in the MANIFEST (a la AssemblyCultureAttribute ).
The way things are named is also important. For example, if you put the neutral language resources in your primary assembly as MyStuff.resources, then the resources in the satellite assemblies must be MyStuff.de.resources (for culture-independent German - something I use quite a bit). The assembly itself must either be MyAssembly.de.dll and/or MyAssembly.dll in a "de" sub-directory.
Once you've got that down, you're on track putting the images in the ResX files (most likely using base64 encoding, which is a good idea for binary data). You can also serialize anything which has a TypeConverter associated with it that can convert to/from strings, like Location and Size properties.
To get a good feel of how all this ties together, try a localization sample using VS.NET. Create a form, set the Localized property to true and design your form using the neutral language, then switch to a new language and override whatever you want. Show hidden files on your project and take a look at them. VS.NET can help with a lot of these tasks, even if you don't use localization functionality provided by the designer (which I don't, because it localizes everything with the LocalizationAttribute set to true, which is quite a lot, making the code run pretty slowly). Finally, compile your example and look at the assembly output, including the MANIFEST for each which you can easily see using ildasm.exe from the .NET SDK).
One more thing: use the NeutralResourcesLanguageAttribute with the culture-specific language (ex: "en-US") so that the Fusion component of the .NET Framework doesn't go looking for your resources contained in your primary assembly, which takes a little extra time - which can be significant when you use touchless-deployment over the web like we're doing with our application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a dialog box implemented in C# and I want to make it the child of the currently active window. For this I want to get the ref to the current windows. I couldn't find anyway so that I could get this ref as Windows.Form object.
One thing I tried was that I used user32.dll GetForegroundWindow() to get the handle to the currently active windows and then use NativeWindow.FromHandle(IntPtr ) method to get the current windows as NativeWindow ref. But in this case I get the handler to the current windiows but the FromHandle method return me always null.
Does anyone know of a way to get the currently active windows?
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
Form.ActiveForm or Form.ActiveMdiChild static methods.
But use myDialogWindow.ShowDialog(this) method I think.
Hi,
AW
|
|
|
|
|
AW,
What I want is a bit different. My application runs in its own memory space and I want to associate it to an application with some differnt memory space. For instance, I have an open word document and I want to associate that word document to my dialog as parent.
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
You can't parent a dialog in one process to another in another process. This isn't possible. The most you can do is position it by getting the currently active window, getting it's position information, and then update your window's position (which should have Form.TopLevel set to true ) so that it appears to be parented.
To get the foreground window, P/Invoke GetForegroundWindow (not GetActiveWindow , which gets the active window attached to the calling thread). You can then P/Invoke GetWindowRect using the IntPtr (representing the HWND ) returned from GetForegroundWindow to get the coordinates of the foreground window and site your window accordingly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello
I am developing a syntax editor .
I need to give auto indentation feature to my editor .
I use C#.And i use richtextbox.
In the key press event ..
I try the following ..
private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// open and close braces indexes
int indexOfOpen;
int indexOfClose;
int lineno;
if (e.KeyValue == 221) // checking for "}" key
{
System.Diagnostics.Trace.WriteLine(this.richTextBox1.GetLineFromCharIndex(this.richTextBox1.SelectionStart).ToString());
// getting line number
lineno = this.richTextBox1.GetLineFromCharIndex(this.richTextBox1.SelectionStart);
while(lineno>0)
{
/*take the previous line from the position of "}" backwards and if it finds "{" charecter .get the
position of "{" charecter and adjust the position of
"}" charecter to the "{" charecter position.
*/
string[] test = this.richTextBox1.Lines;
string previousline = test[lineno-1];
if( previousline.StartsWith("{") )
{
indexOfOpen = previousline.IndexOf("{");
Point pos1 = this.richTextBox1.GetPositionFromCharIndex(indexofopen);
string currentline = test[lineno];
indexOfClose = currentline.IndexOf("}");
Point pos2 = this.richTextBox1.GetPositionFromCharIndex(indexOfClose);
pos2.X = pos1.X;
}
lineno--;
}
}
// check for the enter key
else if(e.KeyValue == 13)
{
string[] contents = richTextBox1.Lines;
int ilen = contents.Length;
string str = contents[ilen-1];
// setting indentation
richTextBox1.SelectionIndent = richTextBox1.SelectionStart;
}
Its somewhere mistake.I am new to C#.
Please can u correct me or give me sample code snippets?
I will be greatly helpful to me.
..
"They can because they think they can" - Voltaire
|
|
|
|
|
kumaru_san wrote:
And i use richtextbox.
Thats not gonna help much as you will realise it is rather limited. Here's what I use:
int GetIndent(string text, int tabsize)
{
if (text == null) return 0;
const char SPACE = ' ' ;
const char TAB = '\t';
int indent = 0, pos = 0, count = 0;
while (pos < text.Length)
{
switch(text[pos++])
{
case SPACE:
count++;
if (count == tabsize)
{
indent++;
count = 0;
}
break;
case TAB:
indent++;
count = 0;
break;
default:
return indent;
}
}
return indent;
}
|
|
|
|
|
dear leppie
thanks for the code snippet.
but i dont understand the logic which u try to explain me through ur code snippet.
Could u comment the source code and send it to me?
Do u think RichTextBox is not good for Line numbering ,auto indentation ,
ruler bar (on top of the text control similar to MS-Word)?
I downloaded xacc AdvancedTextBox also and its so nice ..but takes lot time
to understand the full source code.
Please help me.
"They can because they think they can" - Voltaire
|
|
|
|
|
I am sure there is a simple way to do this, but heck if I can figure it out tonight. Does anyone know of a way to float a child Form (say tool window) in an application properly?
I have a main Form, and I create a new child Form (tool window) with a parent of null and TopMost set to true. This allows my tool window to float over the app nicely. The problem is when I switch to another application, my toolwindow is still staring me in the face since it is TopMost!
How can I make it float topmost only when the application is active? Is there a way to distinguish between the application losing activation because the user switched to another app or because they clicked on the child tool window (which causes a deactivate)?
Any ideas would be greatly appreciated!
Michael
Developer, Author, Chef
|
|
|
|
|
Reset TopMost back to false and set the Owner property of your floating window to the main application form. See the Form.Owner property documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Bah! I knew I was overlooking something simple, but was too brain-fried last night to come up with it. Many thanks again for input Heath!
Michael
Developer, Author, Chef
|
|
|
|
|
hello
I have got a nice doubt to ASK
I have created a user control in C#.net.
and that control is also implementing few interfaces.
but the problem is that ,when i integrate this
control on to a windows form, we can see the user
control for sometime, or days but after few days or
so we can't see it at design time.But is there in the form
at run time. We are using visualstudio 6.0 sourcesafe and
and during integration process most form has got
more than 10 controls. I have mailed it to few discussion
forums but didnt got a satisfying reply.
bye
jithesh
|
|
|
|
|
I wish to know, if there is any way to send an image from one form to another using a socket conection. Say like one form can send an image to another form on a remote computer that recieves it and views it. Can it be done just using sockets? Thanks in advanced 
|
|
|
|
|
One of the overloads for the Image.Save() method takes a System.IO.Stream. You could stream it memory, then send those bits via socket. Something like...
using System.IO;
using System.Net.Sockets;
Bitmap bmp = new Bitmap(@"c:\mypic.gif");
System.IO.MemoryStream memImage = new MemoryStream();
bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Gif);
byte[] data = memImage.ToArray();
Socket socket = new Socket(...your options here...);
socket.Send(data,0,data.Length,SocketFlags.None);
Hope that gets you started!
Michael
Developer, Author, Chef
|
|
|
|
|