|
I have a web service that returns a custom object which contains several arrays of standard types. When I test out the service on the local machine, everything works just fine, the arrays get populated as expected. However, when I add a reference to it in another project on a different machine and invoke it, the return object's arrays all have zero length.
Any ideas? Are there limitations to having an array nested inside a return object from a Web Service?
|
|
|
|
|
Is your CustomObject seen in your client application?
I think you have to decorate your WebMethod (the one that returns the array of CustomObject's) with [SoapInclude(typeof(CustomObject))] .
Calin
|
|
|
|
|
I see the custom object in the client app just fine.
I just tried adding [SoapInclude(typeof(CustomObject))] attribute to the custom object (and yes I did replace "CustomObject" with the actual object), but unfortunately I get the same result. (I also tried it with [XmlInclude(typeof(CustomObject))], same result.) All arrays are zero length and I get the 'out of bounds' error if I try and access any of the elements of an array.
Any other ideas? I haven't been able to find an example of something similar to what I'm doing as far as nesting arrays of common types inside a custom web service return object.
EDIT:
I just tried adding [XmlElement()] attribute to each array property, and the fields in the object became null. I then tried [XmlArray()] instead and got the same result. Here's my object as it exists now:
[SoapInclude(typeof(PingResult))]
[Serializable()]
public class WebMethodResult
{
private Int32 a;
private String[] b;
private UInt32[] c;
private UInt32[] d;
private UInt32[] e;
private Int16[] f;
public Int32 A
{
get { return this.a; }
set { this.a= value; }
}
[XmlArray()]
public String[] B
{
get { return this.b; }
set { this.b= value; }
}
[XmlArray()]
public UInt32[] C
{
get { return this.c; }
set { this.c= value; }
}
[XmlArray()]
public UInt32[] D
{
get { return this.d; }
set { this.d= value; }
}
[XmlArray()]
public UInt32[] E
{
get { return this.e; }
set { this.e= value; }
}
[XmlArray()]
public Int16[] F
{
get { return this.f; }
set { this.f= value; }
}
public WebMethodResult()
{
}
}
modified on Tuesday, February 17, 2009 7:14 PM
|
|
|
|
|
Have you tried deleting the web reference on the client machine and regenerating all of the code? I have never needed any decoration other than Serializable when passing types like this.
BTW, your empty constructor is not the serialization constructor as your comment indicates.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
I have not removed the web reference on the client yet, I've only been updating it as I republish the service with each attempt. I'll give that a whirl, see what happens, and post the results here. Thanks for the suggestion.
I always thought you had to have an empty parameter-less constructor in order for an object to serialize properly. Good to know.
EDIT: I just tried removing and re-adding the web reference, making sure the Settings.Designer.cs file reflected the changes, and still nothing.
Here's the XML from the return object as I see it on the server from the test method. This is what I expect to see on the client side:
<pingresult>
<returncode>1204</returncode>
-
<meternumber>
<string>12081056</string>
<string>12092171</string>
<string>12113456</string>
</meternumber>
-
<amiserialnumber>
<unsignedint>9245344</unsignedint>
<unsignedint>9317678</unsignedint>
<unsignedint>11110689</unsignedint>
</amiserialnumber>
-
<serviceaddresskey>
<unsignedint>500006497</unsignedint>
<unsignedint>500148477</unsignedint>
<unsignedint>500154274</unsignedint>
</serviceaddresskey>
-
<usagepointkey>
<unsignedint>500013896</unsignedint>
<unsignedint>500215109</unsignedint>
<unsignedint>500223149</unsignedint>
</usagepointkey>
-
<meterstatuscode>
<short>1122</short>
<short>1122</short>
<short>1122</short>
</meterstatuscode>
</pingresult>
Well, the xml tags dont show up but imagine these numbers that exist in groups of 3 as being elements of the arrays.
modified on Wednesday, February 18, 2009 4:30 PM
|
|
|
|
|
You are required to have a public default constructor for XML Serialization but it may be implicit. The serialization constructor actually has the signature
public ClassName(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
I just tried adding [XmlInclude{typeof(ReturnType))] to the Web Method, along with combination of the [XmlEment()] and [XmlArray()] tags to the properties but still no go.
Looking at the client, the proxy class that gets generated looks correct too.
|
|
|
|
|
I am trying to get input from a text file and then take out the desired information and place them into variables. Each line is 1 of 3 possible operations performed by a robot. Depending on the desired results these 3 instructions follow a different sequence at which they are performed. Each line will be needed to be read at a time, the values stored, and then move to the next line. I have created the regular expressions need to handle each instruction in the way I want. My problem is, I cant think of a way that would loop the checks to see if what regular expression matches, line by line, so that i can call the right expression to use.
|
|
|
|
|
|
Aren't you using what I gave you?
|
|
|
|
|
ive been already using what you gave me. here is an example of my code:
E 10:45:03 Line 4 : Dispense
tip 1 : dispense 20.56µl 6, 3 Deep Well, landscape [1,1]
10.00µl ">> Water << 23" Fixed <3 - 50µl> Single
E 10:45:05 Line 5 : Wash Tips
wash (2ml + 1ml), grid 20 and grid 20
E shows the beginning operation, and each operator has its own regex structure. I have worked that out so far. The problem is that i want to read the first line, figure out what structure to use, go threw the necessary lines, and then start the process at the next E.
|
|
|
|
|
I had expected you would use what I provided to get the basic information, then once you know the operation from that, use an operation-specific regex to parse the data.
|
|
|
|
|
|
What's not working as you want/expect or what errors are you getting and on which lines?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
You may use Directory.GetFiles(dirname) to get all the files from dirname location. Then loop through returned files and call your code.
Calin
|
|
|
|
|
|
something like this, you should review it because you know what exactly to read from console,...:
...
foreach(string inFile in Directory.GetFiles(filePath))
{
...
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
Console.WriteLine();
Console.WriteLine("Successful file open!...");
Console.WriteLine();
Console.WriteLine("Input file name to save!");
Console.WriteLine("sample: d:\\filename.txt");
filePath = Console.ReadLine();
FileStream file = new FileStream(filePath, FileMode.Create);
StreamWriter sw = new StreamWriter(file);
List lines = new List();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
try
{
int numberOne = Int32.Parse(lines[0]);
int numberTwo = Int32.Parse(lines[1]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberTwo + numberThree;
sw.WriteLine(x);
}
catch { }
sw.Close();
sr.Close();
}
Calin
|
|
|
|
|
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile, filePath;
string line;
foreach (string inFile in Directory.GetFiles(filePath))
{
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
Console.WriteLine();
Console.WriteLine("Successful file open!...");
Console.WriteLine();
Console.WriteLine("Input file name to save!");
Console.WriteLine("sample: d:\\filename.txt");
filePath = Console.ReadLine();
FileStream file = new FileStream(filePath, FileMode.Create);
StreamWriter sw = new StreamWriter(file);
List<string> lines = new List<string>();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
try
{
int numberOne = Int32.Parse(lines[0]);
int numberTwo = Int32.Parse(lines[1]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberTwo + numberThree;
sw.WriteLine(x);
}
catch { }
sw.Close();
sr.Close();
}
}
}
</string></string>
Error:
<br />
Error:<br />
A local variable named 'inFile' cannot be declared in this scope because it would give a different meaning to 'inFile', which is already used in a 'parent or current' scope to denote something else <br />
|
|
|
|
|
Of course...you had to remove first inFile line, because now you are not reading the input file from console.
I just sent you the main idea about how the cose should be changed. Its your task to finish it.
Calin
|
|
|
|
|
this code is only working for a txt files but I want to apply all txt files in a folder its
|
|
|
|
|
problem solved
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile;
string line;
const string inDir = "D:\\data\\A\\";
const string outDir = "D:\\data\\B\\";
DirectoryInfo di = new DirectoryInfo(inDir);
FileInfo[] files = di.GetFiles("*.txt");
foreach (FileInfo fi in files)
{
inFile = fi.FullName;
StreamReader sr = File.OpenText(inFile);
List<string> lines = new List<string>();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
int numberOne = Int32.Parse(lines[0]);
int numberThree = Int32.Parse(lines[2]);
int x = numberOne + numberThree;
sr.Close();
string destFile = Path.Combine(outDir, fi.Name);
File.WriteAllText(destFile, Convert.ToString(x));
}
}
}
</string></string>
|
|
|
|
|
Hi guys,
I have a winform with a public datagridview(dgv1) with some combobox columns.
from a another form i can see the dgv1, but not the columns that i have created into it.
What's that means?
Thanks
|
|
|
|
|
Make sure you have GenerateMember = true and Modifiers = Public for each column.
Calin
|
|
|
|
|
Hi,
I want to write a Sharepoint web service that will run on my Windows Server 2003 as that's what Sharepoint will run on.
I want to write the WS on my local machine which is running VS 2005 on XP and then deploy it to my server. It seems that I need to reference the Sharepoint assembly in my project but I can't install Sharepoint Services 3.0 on my XP machine can I? And that means I can't install the VS 2005 extensions for Sharepoint either.
Do I *have* to do my development on the server itself or what? I'd rather not have to install VS 2K5 on the server just to write one simple WS.
|
|
|
|