ATL Service Web Serice Using XML as Input and Output

F

FS Liu

Hi,

I am writing ATL Service application (XML Web service) in
VS.NET C++.
Are there any sample programs that accept XML as input and
XML as output
in the web service?

Thank you very much.

FS Liu
 
B

Bogdan Crivat [MSFT]

Hi

Please clarify: do you want to load SOAP XML requests as input, and generate
SOAP XML responses as output?

--
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. It is for newsgroup
purposes only.

thanks,
bogdan
 
F

FS Liu

Thanks for your message.

The input to the web service is a set of parameters
which may change in format and the number of variables
for each call. The output variable or the returned
value of the web service is also a set of paramters
which may change in format and the number of variables
as the result of the call.

In my thinking, there are at least two ways to do this:
(1). Pass both input and output as strings in
calling the web service.
In this case, I need to know how to convert
XmlTextReader to string in a very efficient way.
Is this method OK in ATL Server application?
Do I need managed code to do this?
(2). Call web service by passing parameter such as
XmlTextReader or XmlNode type.
But unfortunately, there is too little resources from
Microsoft. Do you have some sample programs ?

Thank you very much.

FS Liu
 
F

FS Liu

Some more clearification:
As I described below, I am thinking to use XML to pass
both the input parameters and output results. I hope
to use both ADO.NET and XML classes for best performance
and development speed.

Thanks again.

FS Liu
 
G

Guest

Hi

Please clarify: do you want to load SOAP XML requests as input, and generate
SOAP XML responses as output?

How about a similar question...

Should (of course I CAN) use ATL Server, VC++7.1 to produce a REST like program?
i.e. from a URL, return an XML doc, which is from my complex C++ objects, and
also be able to PUT/POST HTTP messages that end up back in my C++ program for
processing?

Simple GET example
http://myapp/address?IBM
a get on that would return the address of IBM in my database as a formatted XML
document.

Thanks
sdg
 
F

FS Liu

Are there efficient way (both performance and development
speed) to convert XPathDocument or XmlDocument to string,
or even compress them into binary string for better
internet data transfer performance?

Thanks.

FS Liu



-----Original Message-----
If the params are dynamic, as in FS Liu's example, or if you just want to
pass a XML doc up and return one, why not use a document style of literal?

[
request_handler(name="Default", sdl="GenBlahWSDL"),
soap_handler(
name="BlahService",
namespace="urn:BlahService",
protocol="soap",
style="document",
use="literal" // in order to use style = document, you must
have use = literal
)
]

Then your soap method can look like this:
[ soap_method ]
HRESULT Foo(BSTR foobar, BSTR* retval);

foobar will be your uploaded XML document, and retval will be your return
xml document.

hth

todd brooks




Hi

Please clarify: do you want to load SOAP XML requests
as input, and
generate
How about a similar question...

Should (of course I CAN) use ATL Server, VC++7.1 to
produce a REST like
program?
i.e. from a URL, return an XML doc, which is from my
complex C++ objects,
and
also be able to PUT/POST HTTP messages that end up back
in my C++ program
for
processing?

Simple GET example
http://myapp/address?IBM
a get on that would return the address of IBM in my
database as a
formatted XML
document.

Thanks
sdg


.
[/QUOTE]
 
F

FS Liu

Hi, Bogdan,

I am writing some functions to provide data via
internet with ATL Server structure in VC++.NET.
The input to these functions has the following
feature:
* it may change in data format or/and the number
of variables.
* I am thinking to pass such a dynamic varaible
set with XML doc. The web service will parse
the input XML doc and decide what to do on
server side.
* it may be beter to compress the data before
send it to web server. If this is quite easy
to implement with .NET classes. I will do it.
The output of these functions has the following
feature:
* The results are from SQL Server 2000.
* I want to return the data with XML doc, so
as to use the data cross platform.
* it may be beter to compress the data before
send it back to client. Again, if this is quite
easy to implement with .NET classes. I will do it.
I know that one of the solutions is to implement the
input and output as string or binary string (in the
case of compressed data). But I cannot find an good
example to:
* get data in XML format from SQL Server 2000 in
ATL Server application (by using "for XML"
clause with SQL 2000);
* convert the XML doc to a string in a very
efficient way (instead of node by node by
navigating through the XML tree)
* compress the string into a binary string before
sending it back to client.
* decide a better choice between HTTP GET/POST and
ATL Server web service (I am not sure if I should
go to web service wizard project for this. But
I am sure I want to use ATL server project for
beter performance.).

Please advise.

Thank you very much.

FS Liu


-----Original Message-----
Could you please provide a few more details on the functionality of your
app?
Looks like the HTTP Client class in ATL Server could be of help here

--
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. It is for newsgroup
purposes only.

thanks,
bogdan
as input, and
generate
How about a similar question...

Should (of course I CAN) use ATL Server, VC++7.1 to
produce a REST like
program?
i.e. from a URL, return an XML doc, which is from my
complex C++ objects,
and
also be able to PUT/POST HTTP messages that end up back
in my C++ program
for
processing?

Simple GET example
http://myapp/address?IBM
a get on that would return the address of IBM in my
database as a
formatted XML
document.

Thanks
sdg


.
[/QUOTE]
 
B

Bogdan Crivat [MSFT]

Hi,

The problems that I understand need solving are:
1. compression (in and out)
2. reading variable XML description of the parameters from the input
3. getting SQL 2000 data as XML
4. render the response as a stream



1. Compression -- I think this can be solved by using IISs compression
abilities. I think IIS comes with an ISAPI filter that allows zip
compression for in/out traffic.
If not, you could easily overwrite the ATLServer ISAPI buffer response class
to compress the content on the fly and add a custom header to the response


For the main part of the job (reading the input and generating the streamed
output) -- one way to go is to modify the ATL Server SOAP support framework.
It is possible to completely override the SOAP input parameter parsing (and
get control by using your custom SAX handler instead of ATLS's one). Also,
it is possible to write directly to the response stream and override the
SOAP response serialization mechanism. If you think you really need to do
this and override the SOAP support, please let me know, the rest of this
messsage is about a different solution)

However, the SOAP support is intended to help in RPC/COM like invocations of
SOAP methods (with IDL support for structs, in/out parameters and basic
types).
Your application seems to have a more specialized function: get some POSTed
XML input which contains a query description (or so) , execute the query and
stream the XML from SQL Server as response.
You could just not use the ATLS SOAP support, but create a regular
(non-soap) web application and parse yourself the input XML (which may or
may not be strictly respecting the SOAP format).
Once you parse the input parameters, you can build your query and execute it
against SQL Server. The 'FOR XML AUTO' response from SQL Server can be
fetched as an IStream interface through OLEDB and, as you read from that
stream, you can render data back to the caller (by writing it to the
m_HttpResponse buffer).
The code should look like below (connecting to Northwind,

#define CONNECTION_STRING L"Provider=SQLOLEDB.1; Integrated Security=SSPI;
Data Source=localhost; Initial Catalog=Northwind"
#define CHECK_ERROR(x) (hr=x; if (!SUCCEEDED(hr))goto err;)

HRESULT hr;
CDataSource dataSrc;
CSession session;
CCommand<CNoAccessor, CStreamRowset> cmd;

CHECK_ERROR(dataSrc.OpenFromInitializationString(CONNECTION_STRING));
CHECK_ERROR(session.Open(dataSrc));

CHECK_ERROR(cmd.Open(session, "SELECT * from Customers FOR XML AUTO"));

CHAR buff[1024 + 1];
ULONG cbRead = 1024;
do
{
CHECK_ERROR(cmd.m_spStream->Read( buff, 1024, &cbRead));
buff[cbRead] = '\0';
m_HttpResponse.Write(buff);
}while( cbRead == 1024 );
err:
return SomeError;


This way, the XML data coming from the SQL Server is directly streamed to
the HTTP response without loading it into intermediary XML classes (either
unmanaged DOM or .Net)


So, if you decide to go with this second approach (regular web application
instead of using the SOAP support), you 'll get:
- good performance for writing the query result as XML back to the caller,
without using intermediate classes and without intermediate copy operations
- good database connection performance (ATL Server has a mechanism to cache
database connections)
- ability to expose a SOAP -like behavior for the clients (without actually
using the ATL Server SOAP support) -- you will have to parse the input and
make sure it looks like <soap:Envelope... etc
Also, to implement SOAP you will have to wrap the response from the SQL
Server in a <soap:Envelope><soap:Body> set of tags
- ability to switch with minimal effort to a HTTP GET behavior (you'll just
need to get the parameters from the QueryString collection instead opf
parsing a POSTed input XML document)

Besides, you don't need to modify the ATLS SOAP framework
Please let me know if this works for you and if you would like a small
working sample of this

Optimization suggestion:
- the SQL Server connection should be cached in the ISAPI DLL (the ATLS
wizard allows you to create a database connection cache in the ISAPI dll)
- if you decide to have POST-ed XML as input (instead of HTTP GET or POST
parameters), you could use the per-thread ISAXXMLReader that available in
ISAPI DLLs
- you might want to change the default buffer size for the HTTP Response
depending on the values you use when reading from the CStreamRowset in the
code above


--
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. It is for newsgroup
purposes only.

thanks,
bogdan
 
F

FS Liu

Hi, bogdan,

Your message is very helpful in showing me the direction
and some details. I don't have an immediate feeling of
the difference in the performance of the two methods you
described. Could you please show me how to override
SOAP support? I will also try the second approach by
myself to see what the performance difference between
the two methods looks like.


Thank you very much.

FS Liu

-----Original Message-----
Hi,

The problems that I understand need solving are:
1. compression (in and out)
2. reading variable XML description of the parameters from the input
3. getting SQL 2000 data as XML
4. render the response as a stream



1. Compression -- I think this can be solved by using IISs compression
abilities. I think IIS comes with an ISAPI filter that allows zip
compression for in/out traffic.
If not, you could easily overwrite the ATLServer ISAPI buffer response class
to compress the content on the fly and add a custom header to the response


For the main part of the job (reading the input and generating the streamed
output) -- one way to go is to modify the ATL Server SOAP support framework.
It is possible to completely override the SOAP input parameter parsing (and
get control by using your custom SAX handler instead of ATLS's one). Also,
it is possible to write directly to the response stream and override the
SOAP response serialization mechanism. If you think you really need to do
this and override the SOAP support, please let me know, the rest of this
messsage is about a different solution)

However, the SOAP support is intended to help in RPC/COM like invocations of
SOAP methods (with IDL support for structs, in/out parameters and basic
types).
Your application seems to have a more specialized function: get some POSTed
XML input which contains a query description (or so) , execute the query and
stream the XML from SQL Server as response.
You could just not use the ATLS SOAP support, but create a regular
(non-soap) web application and parse yourself the input XML (which may or
may not be strictly respecting the SOAP format).
Once you parse the input parameters, you can build your query and execute it
against SQL Server. The 'FOR XML AUTO' response from SQL Server can be
fetched as an IStream interface through OLEDB and, as you read from that
stream, you can render data back to the caller (by writing it to the
m_HttpResponse buffer).
The code should look like below (connecting to Northwind,

#define CONNECTION_STRING L"Provider=SQLOLEDB.1; Integrated Security=SSPI;
Data Source=localhost; Initial Catalog=Northwind"
#define CHECK_ERROR(x) (hr=x; if (!SUCCEEDED(hr))goto err;)

HRESULT hr;
CDataSource dataSrc;
CSession session;
CCommand<CNoAccessor, CStreamRowset> cmd;

CHECK_ERROR(dataSrc.OpenFromInitializationString (CONNECTION_STRING));
CHECK_ERROR(session.Open(dataSrc));

CHECK_ERROR(cmd.Open(session, "SELECT * from Customers FOR XML AUTO"));

CHAR buff[1024 + 1];
ULONG cbRead = 1024;
do
{
CHECK_ERROR(cmd.m_spStream->Read( buff, 1024, &cbRead));
buff[cbRead] = '\0';
m_HttpResponse.Write(buff);
}while( cbRead == 1024 );
err:
return SomeError;


This way, the XML data coming from the SQL Server is directly streamed to
the HTTP response without loading it into intermediary XML classes (either
unmanaged DOM or .Net)


So, if you decide to go with this second approach (regular web application
instead of using the SOAP support), you 'll get:
- good performance for writing the query result as XML back to the caller,
without using intermediate classes and without intermediate copy operations
- good database connection performance (ATL Server has a mechanism to cache
database connections)
- ability to expose a SOAP -like behavior for the clients (without actually
using the ATL Server SOAP support) -- you will have to parse the input and
make sure it looks like <soap:Envelope... etc
Also, to implement SOAP you will have to wrap the response from the SQL
Server in a <soap:Envelope><soap:Body> set of tags
- ability to switch with minimal effort to a HTTP GET behavior (you'll just
need to get the parameters from the QueryString collection instead opf
parsing a POSTed input XML document)

Besides, you don't need to modify the ATLS SOAP framework
Please let me know if this works for you and if you would like a small
working sample of this

Optimization suggestion:
- the SQL Server connection should be cached in the ISAPI DLL (the ATLS
wizard allows you to create a database connection cache in the ISAPI dll)
- if you decide to have POST-ed XML as input (instead of HTTP GET or POST
parameters), you could use the per-thread ISAXXMLReader that available in
ISAPI DLLs
- you might want to change the default buffer size for the HTTP Response
depending on the values you use when reading from the CStreamRowset in the
code above


--
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. It is for newsgroup
purposes only.

thanks,
bogdan


Hi, Bogdan,

I am writing some functions to provide data via
internet with ATL Server structure in VC++.NET.
The input to these functions has the following
feature:
* it may change in data format or/and the number
of variables.
* I am thinking to pass such a dynamic varaible
set with XML doc. The web service will parse
the input XML doc and decide what to do on
server side.
* it may be beter to compress the data before
send it to web server. If this is quite easy
to implement with .NET classes. I will do it.
The output of these functions has the following
feature:
* The results are from SQL Server 2000.
* I want to return the data with XML doc, so
as to use the data cross platform.
* it may be beter to compress the data before
send it back to client. Again, if this is quite
easy to implement with .NET classes. I will do it.
I know that one of the solutions is to implement the
input and output as string or binary string (in the
case of compressed data). But I cannot find an good
example to:
* get data in XML format from SQL Server 2000 in
ATL Server application (by using "for XML"
clause with SQL 2000);
* convert the XML doc to a string in a very
efficient way (instead of node by node by
navigating through the XML tree)
* compress the string into a binary string before
sending it back to client.
* decide a better choice between HTTP GET/POST and
ATL Server web service (I am not sure if I should
go to web service wizard project for this. But
I am sure I want to use ATL server project for
beter performance.).

Please advise.

Thank you very much.

FS Liu




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top