|
|
I have the following SOAP data (which I have no control over):
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Logon xmlns="http://www.domain.com/EP/">
<userId>int</userId>
<strPassword>string</strPassword>
<strSessionId>string</strSessionId>
</Logon>
</soap:Body>
</soap:Envelope>
I need to be able to parse through this to extract the childnode values of <Logon>, and place these into a sorted list. Simple I thought, but namespaces are causing me some problems :
SortedList GetLogonData(string soapData)
{
XmlDocument soapDataXdoc = new XmlDocument();
soapDataXdoc.LoadXml(soapData);
XmlNamespaceManager nsMgr = new XmlNamespaceManager(soapDataXdoc.NameTable);
nsMgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsMgr.AddNamespace("", "http://www.domain.com/EP/");
XmlNode logonNode = soapDataXdoc.SelectSingleNode("soap:Envelope/soap:Body/Logon", nsMgr);
SortedList returnValue = new SortedList();
foreach(XmlNode xn in logonNode.ChildNodes)
{
returnValue.Add(xn.Name, xn.InnerText);
}
return returnValue;
}
In theory this should return a sorted list with the following values
userId - int
strPassword - string
strSessionId - session
But when I retrieve the logonNode this returns null, which I believe is being caused by an incorrect xpath, but I do not know why it is incorrect.
Could anybody point me in the right direction?
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
Using an empty namespace prefix doesn't work in .NET 1.x. Specify a namespace prefix in your code. The namespace prefixes don't have to match, so you can have the default namespace in your <Logon> element but use a namespace prefix in your code.
Also, to avoid adding the other namespaces, you could always add the namespace with a prefix (let's say "l") and just use an XPath expression like "//l:Logon" to get the node. Just a thought.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Not sure if I undertstood correctly, but I have essentially modified my code to the following :
XmlNamespaceManager nsMgr = new XmlNamespaceManager(soapDataXdoc.NameTable);
nsMgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsMgr.AddNamespace("blank", "http://www.domain.com/EP/");
XmlNode logonNode = soapDataXdoc.SelectSingleNode("soap:Envelope/soap:Body/blank:Logon", nsMgr);
Also tried this :
nsMgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsMgr.AddNamespace("blank", "http://www.domain.com/EP/");
XmlNode bodyNode = soapDataXdoc.SelectSingleNode("soap:Envelope/soap:Body", nsMgr);
foreach(XmlNode xn in bodyNode.ChildNodes)
{
xn.Prefix = "blank";
}
XmlNode logonNode = soapDataXdoc.SelectSingleNode("soap:Envelope/soap:Body/blank:Logon", nsMgr);
Actually I definately didnt understand, as that didnt work
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
If you select a node using the XmlDocument instead of the DocumentElement , you must use a beginning "/" which uses a scope from the root element. The following sample works fine:
using System;
using System.Xml;
public class Test
{
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("Test.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("l", "http://www.domain.com/EP/");
XmlNode logonNode = doc.SelectSingleNode(
"/soap:Envelope/soap:Body/l:Logon", nsmgr);
if (logonNode != null)
{
foreach (XmlNode child in logonNode.ChildNodes)
Console.WriteLine("{0}: {1}", child.Name, child.InnerText);
}
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want that while editing the textBox when I reach the edge
of the column to automaticly start a new line and when
finished that the text will be displayed that way.
|
|
|
|
|
I'm pulling out what little remaining hair I have again. I have a list box with 8 items, the selected item is highlighted at the top of the list. I press a button (cmdMoveDown) and wish to move the selected item 1 item down the list.
I tried this:
public void MoveDown()<br />
{<br />
int index = this.lstSelected.SelectedIndex;<br />
int newindex = index + 1;<br />
<br />
DataTable dtSelect = (DataTable)this.lstSelected.DataSource;<br />
DataRow dr = dtSelect.Rows[index];<br />
<br />
dtSelect.Rows.Remove(dr);<br />
dtSelect.Rows.InsertAt(dr, newindex);<br />
}
this removes the item at index 0 just fine. But the insert doesn't happen and there is a blank line at the bottom of the list.
then i tried this variation:
public void MoveDown()<br />
{<br />
int index = this.lstSelected.SelectedIndex;<br />
int newindex = index + 1;<br />
<br />
DataTable dtSelect = (DataTable)this.lstSelected.DataSource;<br />
DataRow dr = dtSelect.Rows[index];<br />
DataRow drNew = dtSelect.NewRow();<br />
<br />
foreach(DataColumn dc in dtSelect.Columns)<br />
drNew[dc.ColumnName] = dr[dc.ColumnName];<br />
<br />
dtSelect.Rows.Remove(dr);<br />
dtSelect.Rows.InsertAt(drNew, newindex);<br />
}
this variation removed the selected item and added the new row at the end of the list rather than at new index.
I tried various permutations of this code and could get nothing to work. Any suggestions?
|
|
|
|
|
A lot of this depends on how your data source is bound to the ListBox . When you update your DataTable like that, the changes may not be reflected in the ListBox . See the CurrencyManager for more information about a way to refresh the bindings, like calling Refresh on the CurrencyManager you can get from the ListBox.BindingContext (inheritted from the Control class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay. I traced through the previously posted code and the data is actually being inserted into the table correctly and at the correct position. It is the DefaultView which is causing the list to display in the wrong order.
I added the following to the method:
CurrencyManager cmSelect = (CurrencyManager)this.lstSelected.BindingContext(dtSelect);<br />
cmSelect.Refresh();
It runs without error, but nothing changes. Can anyone suggest another approach?
|
|
|
|
|
Then create a DataView on the table and set that as the DataSource .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm Developing a WebApplication in which i have to pass parameter to DLL present in a remote computer and return the values returned by the DLL to the user... someone please help me in doing this....
|
|
|
|
|
You can't load a DLL from a remote computer and have it executed on the remote computer. You need some sort of RPC (remote procedure call), such as DCOM, COM+, .NET Remoting (preferred in .NET applications), or Web Services (if the other machine has IIS installed). In those cases you could P/Invoke the exported function from that DLL (if it's native), thus wrapping the unmanaged function in a managed class (or a native DCOM or COM+ executable).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I was thinking of combining a Diffgram Dataset with using Web Services. From my readings I noticed that I can save a dataset as a diffgram to a file after I do updates/inserts/deletes on the dataset. Then when I need to do more updates/inserts I reread the diffgram into a dataset and if I am connected to a database then use a dataadapter to update the database with changes. Is this correct in my assumption of how I can use the diffgram? I would create a Web Service to accept the Diffgram Dataset and have it create a DataAdapter to update the database. How does this sound? Any ideas?
Thanks,
JJ
|
|
|
|
|
You could do this with a diffgram, but the DataSet and DataAdapter derivatives already support changes. Lets say that your client made changes to a DataSet it original got from a web service. To send the changes call DataSet.GetChanges to get just the changes (optionally, but decreases bandwidth consumption) and then pass the DataSet back to the web service. The web service could call DataAdapter.Update on the DataSet and optionally return the DataSet back to the client (in case there were changes made by other clients, etc.
Just be sure you don't call AcceptChanges otherwise all change information is lost. DataAdapter.Update does this automatically after updating the database. The DataAdapter should have all four command properties defined, and it's common to combine an INSERT and SELECT statement (separated by a semi-colon (;)) so that any auto-generated information (or default values) are included in the DataSet .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
Ok, but this is for an alternative to my semi Offline connection problem. So I would try to contact a web service sitting on the server and if it can't make a connection then have the dataset write out to a diffgram xml file. If I can make a connection then send Diffgram dataset to web service to update database by using DataAdapter in web service. How does that sound, Heath?
Thanks,
JJ
|
|
|
|
|
Fine, but why write-out the diffgram at all, unless you're worried about your application being closed. That's understandable.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, I'm not worried about the App being closed. But if connection can't be made to web service on server where do I store the dataset once data is entered in app? I assume just use a normal dataset if not going with diffgram to store locally? Also if I did use a diffgram dataset, this would be the same as replication to database on server. The web service dataadapter would check changes and only pass the inserts/updates etc. to db.
JJ
|
|
|
|
|
Just keep it in memory as an object and keep adding/updating/deleting rows. Once a connection can be established, then send the diffgram (remember, don't ever call AcceptChanges or you won't have a diffgram! ). If you want to save this in case the application is closed, make sure you write out the diffgram using XmlWriteMode.DiffGram and read it back in later.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok now I got what you are saying. Yes the application will be closed once done entering in info. This is done on a daily basis and having the PDA on all day doesn't make sense.
Thanks Heath,
JJ
|
|
|
|
|
Note, just because a PDA appears off doesn't mean the memory state isn't saved. This is how they work - unless you physically turn off the device, it is always on - it is just sleeping or hibernating. When you turn it on, every program is still running as it was before. How do you think they can notify you of events when they appear off?
Also, even when you close an application using the X button at the top, the application is still running (unless you're using a single process build of Windows CE - but PocketPC is a multi-process build). It isn't terminated unless you use the Memory control panel app to terminate it or your program terminates itself (or has a critical error and dies).
A few things to keep in mind.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello all,
My requirement:: There's protocol Interface class with some persistant data which has to be invoked from seveal other classes with out disturbing the Member data. In Visual C++ windows application we create new instance of Protocol Class in the Application main class.... & gets reference of this where ever we are using it.... like
CProtocolAPI *pProtocol = (TestApp*)AfxGetApp()->m_pProtocol
and we can call methods of CProtocolAPI using pProtocol reference
now my doubt is how can i do this in C#.... can any body give me some idea..... little urgent plzzzzzzzzz
Thanku in advance
Adi
|
|
|
|
|
Store a static instance of ProtocolInterface inside your main class and create a static property to access it.
<br />
public class Main<br />
{<br />
private static ProtocolInterface protocol;<br />
public static ProtocolInterface Protocol<br />
{<br />
get<br />
{<br />
return Main.protocol;<br />
}<br />
}<br />
}<br />
Access the instance by Main.Protocol
Does this help?
|
|
|
|
|
I have three forms a parent form, child form 1, child form2. Child form1 is a user interface used to save data to the random access file .The user inputs the following in to the textboxes Name, Account Number, & Address. Child form2 reads the file. That works fine but I would like to use a combobox to display the name and account number, so when the user selects the name & account nuber the textboxes are filled with the appropriate data. Is this possible? Any help would be greatly appreciated.
|
|
|
|
|
my way:
public dataset owned by parentform, with all the data you need in both childs. So even if user changes data from 1st child, data in the 2nd one are immediately available. That's a little faster: no need to save/read/synchronize two datasources. And no need to write your own save to file/load/parse etc. stuff.
h.
|
|
|
|
|
I am importing data from a excel sheet to a listview box. I need to set the range of the listview column to the no of columns available in the excel sheet.
I am able to count the available no of columns in the excel sheet using worksheet.columns.count.
The worksheet.get_range(object cell1, object cell2) asks for the the starting column ie A to the end column which could be anything from B to ZZ and so on.
The solution I could see is add the worksheet.column.count value to 65(ascii code of A). But how do i convert back the value say 77 to its equivalent Ascii char M. I dont find any toascii() function.
Regards
Tarakeshwar
CCIE Q(Routing and Switching), MCSE Security
|
|
|
|