Hi Luke
Basically the DATA provider who is posting data to our URL has sent this
sample code showing HOW TO RECIEVE THEIR DATA - could you please guide me to
convert this code to ASP perhaps this is c# which I am not aware. Here is
the sample code:
======================================
private enum ReturnCode { Success, Error, NoData, FileIOError };
private void Page_Load(object sender, System.EventArgs e)
{
ReturnCode returnCode = ReturnCode.Success;
try
{
returnCode = Upload();
}
catch
{
returnCode = ReturnCode.Error;
}
finally
{
Response.Output.Write( "<result><returnCode>{0}</returnCode></result>",
returnCode );
}
}
private ReturnCode Upload()
{
ReturnCode returnCode = ReturnCode.Success;
//
// Make sure we have something to work with
//
int bLen = Context.Request.ContentLength;
if( bLen > 0 )
{
//
// The body contains XML formatted as ADF...
// so convert the bytes to string.
//
byte[] bytes = Context.Request.BinaryRead( bLen );
string msg = Encoding.ASCII.GetString( bytes, 0, bLen );
//
// At this point we have some data and we expect
// it to be an ADF report, which is valid XML.
//
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager( nt );
XmlParserContext pc = new XmlParserContext( null, nsmgr, null,
XmlSpace.None );
XmlValidatingReader xmlReader = new XmlValidatingReader( msg,
XmlNodeType.Document, pc );
//
// The Microsoft XML parser cannot resolve the
// colorcombination element... so for now, just
// disable the validation.
//
xmlReader.ValidationType = ValidationType.None;
//
// Load the document
//
XPathDocument xDoc = new XPathDocument( xmlReader );
XPathNavigator nav = xDoc.CreateNavigator();
//
// Find the call id so that we can use it as a filename.
//
string cdrID = null;
XPathNodeIterator iter = nav.Select( "/adf/prospect" );
while( iter.MoveNext() && cdrID == null )
{
XPathNodeIterator prospectIter = iter.Current.SelectChildren(
XPathNodeType.Element );
while( prospectIter.MoveNext() )
{
if( string.Compare( prospectIter.Current.Name, "id", true ) == 0 )
{
cdrID = prospectIter.Current.Value;
break;
}
}
}
try
{
if( cdrID != null )
{
string dir = ConfigurationSettings.AppSettings[ "DataFileDir" ];
if( dir == null || dir.Length == 0 )
{
// default to the current directory
dir = ".";
}
string fileName = string.Format( @"{0}\{1}.xml", dir, cdrID );
using( StreamWriter writer =
new StreamWriter( new FileStream( fileName, FileMode.Create ),
System.Text.Encoding.ASCII ) )
{
writer.WriteLine( msg );
}
}
}
catch
{
returnCode = ReturnCode.FileIOError;
}
}
else
{
returnCode = ReturnCode.NoData;
}
return returnCode;
}
================================================
Thanks much!
Garyrek
"Garyrek" <Ga*****@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
Well Luke, we don't have any control on the xml file as it is provided by
the service provider and they won't change as it is working for their
other clients. NOW the deal is to make it work without changing any - I think I
got over the doctype node by setting resolveexternals and validateonparse
to false however I encountering with "Switch from current encoding to
specified encoding not supported." while posting the xml file - please remember that
posting is just for testing our MAIN job is to receive the data since they
are posting it to our URL
We do have tech support - what is the number I call, thanks
"[MSFT]" <lu******@online.microsoft.com> wrote in message
news:T1*************@cpmsftngxa06.phx.gbl... Hi Gary,
With deeper research on this issue, I found the problem is related to AS
P application's permission. I test the XML data and code in a windows
application:
Dim xmldoc, data
Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument.4.0")
xmldoc.async = False
xmldoc.resolveExternals = True
xmldoc.validateOnParse = True
Dim ss
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim ff
Set ff = fso.OpenTextFile("c:\case\edit1.xml")
ss = ff.readall
ff.Close
MsgBox xmldoc.loadxml(ss)
xmldoc.save ("c:\case\saved1.xml")
Above code work great. But when I move them in an ASP application, it
can't load the XML data.
Then I put the dtd file in local disk:
<!DOCTYPE adf SYSTEM "c:\adfdtd.dtd">
And then, the asp application begin to work.
Therefore, the root cause of the problem should be that the ASP
application doesn't have enough permission to access DTD on internet, it can only
access on local disk. You may try this on your side.
Additionally, resolveExternals should be set to true on both of client
and server side:
objXMLDocument.resolveExternals = True
Luke
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)