I have some (at 5 years) experience in Delphi (30 years in pascal) but not so much in WEB programming. I have installed FTP (file transfer) and SMTP (mailing) support into some of my programs, with success. Also I have used HTTP (Get) and then parsed some strings, also with success. But, that's it!
Now I had to connect to https (secure) url and use ASMX service to send and receive XML files. The file is ok and have been tested.
But.. I almost don't have a clue how to implement this sort of connection with Delphi 7. I suspect SOAP (simple object access protocol) and that suspect-ion is raised from this example here below, where it creates objects "out of thin air" without none visual classes, but I'm not sure!
The written example is in C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace SendaStgrXML
{
public partial class AAmain : Form
{
public AAmain()
{
InitializeComponent();
}
private string FileLoc = null;
private void AAmain_Load(object sender, EventArgs e)
{
}
private void btnSend_Click(object sender, EventArgs e)
{
Stream strm;
try
{
// Test:
string url = @"https://securep.rsk.is/stadgreidsla/stadgreidslaws/thjonusta.asmx";
// Life:
//string url = @"https://secure.rsk.is/stadgreidsla/stadgreidslaws/thjonusta.asmx";
//proxyStadgreidslaWSE.Stadgreidsla stadgr = new proxyStadgreidslaWSE.Stadgreidsla();
Stadgr.Stadgreidsla stadgr = new SendaStgrXML.Stadgr.Stadgreidsla();
OpenFileDialog ofd = new OpenFileDialog();
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() != DialogResult.OK)
{
MessageBox.Show("Hætt við");
return;
}
开发者_Python百科 if ((strm = ofd.OpenFile()) == null)
{
MessageBox.Show("Engin skrá");
return;
}
Stadgr.Thjonusta thjon = new SendaStgrXML.Stadgr.Thjonusta();
thjon.Url = url;
/* byte[] test = new byte[2000];
strm.Read(test, 0, 2000);
MessageBox.Show(ConvertByteArrayToString(test));*/
XmlSerializer s = new XmlSerializer(typeof(SendaStgrXML.Stadgr.Stadgreidsla),
"http://rsk.is/rafraenstadgreidsla/");
//stadgr = (SendaStgrXML.Stadgr.Stadgreidsla)s.Deserialize(strm);
strm.Close();
// This call is for error checking.
SendaStgrXML.Stadgr.VilluprofaSkilagreinResponseSvarVilluprofun svar =
new SendaStgrXML.Stadgr.VilluprofaSkilagreinResponseSvarVilluprofun();
svar = thjon.VilluprofaSkilagrein(stadgr);
// This one is for actual transmission of data:
SendaStgrXML.Stadgr.SendaSkilagreinResponseSvar svar =
new SendaStgrXML.Stadgr.SendaSkilagreinResponseSvar();
svar = thjon.SendaSkilagrein(stadgr);
// Does not apply to you:
/*SendaStgrXML.Stadgr.SendaSkilagreinLokadArResponseSvar svar =
new SendaStgrXML.Stadgr.SendaSkilagreinLokadArResponseSvar();
svar = thjon.SendaSkilagreinLokadAr(stadgr);*/
MessageBox.Show(svar.Villubod);
if (svar.Skilagildi !=-1)
MessageBox.Show("Sending tókst");
else
MessageBox.Show("Sending tókst ekki: " +
svar.Villubod);
}
catch (Exception er)
{
MessageBox.Show(er.ToString());
}
}
public static string ConvertByteArrayToString(byte[] byteArray)
{
return (new ASCIIEncoding()).GetString(byteArray);
}
private void btnForsendur_Click(object sender, EventArgs e)
{
Forsendur fs = new Forsendur();
fs.Saekja();
}
private void btnEldra_Click(object sender, EventArgs e)
{
Forsendur fs = new Forsendur();
fs.Saekja_Eldra();
}
}
Update:
I will try to describe my problem in more detail and hopefully better.
I write in Delphi, Delphi 7 as today. I have a rather simple task, that is to implement a connection to Web service.
The main goal is to send XML file and then receive an answer (also XML file).
I looked into XML data binding Wizard and found out I have no schema-file for the wizard. Stop there.
I must state that I don't need any help to parse or write XML files, I can build lists of objects just as easily if I like by myself. In this case I don't need to. (To me XML is just a Ascci file of 1..n levels of blocks and I have already build an abstract methods to receive properties of data of "n-th" values in such a files)
Back to the problem..
I have a c# code but can't figure it out. For example I don't see any classes or schema to build any objects at runtime, maybe it is just missing?
At least. If some one here can help me (in this fantastic place as Stack Overflow is) how to communicate with such a kind of WEB service, then I would appreciated very much. It was on my schedule to finish this before 15th, that is a final day for monthly tax delivery day here in Iceland.
The language appears to be C#. You can use Delphi's XML Data Binding Wizard (File->New->Other->XML) to import the XML.
If this is actually SOAP, you might be able to use the WSDL importer (File->New->Other->WebServices->WSDL Importer) to build the classes for you.
精彩评论