469,286 Members | 2,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Capture XML Response

I am writing a C# Windows service that calls methods on a remote web service
and would like to capture the XML returned by the web service. The reason I
need the raw XML is for back up to the sub-set of data I am saving to a
database.

All the posts I have found seem to assume one has access to both the client
and server applications but since the web service is remote, I can only
control the client side.

Any help in learning how to accomplish this will be greatly appreciated.

Thanks,
Tom
Jan 11 '07 #1
12 14331
Send a regular HTTP POST request to the web server that will call the
appropriate web service, and read the returned XML as a stream.

Do you have the URL of the web service? If yes, try to type that URL in your
web browser. It will display the proper format of the HTTP request, so you
can use it.

"Tom Bean" <tb***@newsgroup.nospamwrote in message
news:up**************@TK2MSFTNGP04.phx.gbl...
>I am writing a C# Windows service that calls methods on a remote web
service and would like to capture the XML returned by the web service. The
reason I need the raw XML is for back up to the sub-set of data I am saving
to a database.

All the posts I have found seem to assume one has access to both the
client and server applications but since the web service is remote, I can
only control the client side.

Any help in learning how to accomplish this will be greatly appreciated.

Thanks,
Tom


Jan 11 '07 #2
Ashot,

I call the methods using a WebReference object, created from a WSDL file,
not with HTTP POST. There is a charge for each call to the web service so I
can't afford to make the call both ways to get the data and the XML.

Tom

"Ashot Geodakov" <a_********@hotmail.comwrote in message
news:uY**************@TK2MSFTNGP06.phx.gbl...
Send a regular HTTP POST request to the web server that will call the
appropriate web service, and read the returned XML as a stream.

Do you have the URL of the web service? If yes, try to type that URL in
your web browser. It will display the proper format of the HTTP request,
so you can use it.

"Tom Bean" <tb***@newsgroup.nospamwrote in message
news:up**************@TK2MSFTNGP04.phx.gbl...
>>I am writing a C# Windows service that calls methods on a remote web
service and would like to capture the XML returned by the web service.
The reason I need the raw XML is for back up to the sub-set of data I am
saving to a database.

All the posts I have found seem to assume one has access to both the
client and server applications but since the web service is remote, I can
only control the client side.

Any help in learning how to accomplish this will be greatly appreciated.

Thanks,
Tom



Jan 11 '07 #3
Check out the MSDN docs:
ms-help://MS.MSSDK.1033/MS.NETFX30SDK.1033/cpref26/html/T_System_Web_Services_Protocols_SoapExtension.htm

Shows using a SoapExtension on the client side (your windows service) to
write outgoing and incoming XML between client and service.

Ron

"Tom Bean" <tb***@newsgroup.nospamwrote in message
news:up**************@TK2MSFTNGP04.phx.gbl...
>I am writing a C# Windows service that calls methods on a remote web
service and would like to capture the XML returned by the web service. The
reason I need the raw XML is for back up to the sub-set of data I am saving
to a database.

All the posts I have found seem to assume one has access to both the
client and server applications but since the web service is remote, I can
only control the client side.

Any help in learning how to accomplish this will be greatly appreciated.

Thanks,
Tom


Jan 11 '07 #4
Hello Tom,

Normally, for interactive diagnostic, we will use some trace utiilty like
tcptrace , soaptoolkit+traceutility. For your scenario, if you want to
programmatically capture the message and log it, you can consider using
soapExtension as Ron suggested. Soap Extension can be used at both
clientside and server-side of webservice. Here are some reference articles
you can have a look.

#Fun with SOAP Extensions
http://msdn2.microsoft.com/en-us/library/ms972353.aspx

#Using SOAP Extensions in ASP.NET
http://msdn.microsoft.com/msdnmag/is...n/default.aspx

#How to: Implement a SOAP Extension
http://msdn2.microsoft.com/en-us/library/7w06t139.aspx

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Jan 12 '07 #5
Ron,

I had looked at the TraceExtension sample before I submitted my post and
have tried to implement it in my application. The problem I'm having is
that I couldn't find the code that uses TraceExtension. How do you
implement it and make sure it gets called during the web service request and
response?

Also, I notice the document says "SOAP extensions for XML Web services
created using ASP.NET." I am not creating a web service and I am not using
ASP.NET. My application is a Windows application, so how do I implement
something like TraceExtension in it?

Tom

"RYoung" <r@gmail.comwrote in message
news:uk**************@TK2MSFTNGP06.phx.gbl...
Check out the MSDN docs:
ms-help://MS.MSSDK.1033/MS.NETFX30SDK.1033/cpref26/html/T_System_Web_Services_Protocols_SoapExtension.htm

Shows using a SoapExtension on the client side (your windows service) to
write outgoing and incoming XML between client and service.

Ron

"Tom Bean" <tb***@newsgroup.nospamwrote in message
news:up**************@TK2MSFTNGP04.phx.gbl...
>>I am writing a C# Windows service that calls methods on a remote web
service and would like to capture the XML returned by the web service.
The reason I need the raw XML is for back up to the sub-set of data I am
saving to a database.

All the posts I have found seem to assume one has access to both the
client and server applications but since the web service is remote, I can
only control the client side.

Any help in learning how to accomplish this will be greatly appreciated.

Thanks,
Tom



Jan 12 '07 #6
Steven,

All the documentation I've seen, including the articles you sent, say SOAP
extensions are implemented on the web site. I have no access to the web
site where the web service runs. I need to capture the XML in the request
and response on the client.

I must be missing something but I haven't seen anything that shows how to
implement a SOAP extension in a Windows client application. Is it possible
to do this without having access to the web service?

Tom

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:Dm**************@TK2MSFTNGHUB02.phx.gbl...
Hello Tom,

Normally, for interactive diagnostic, we will use some trace utiilty like
tcptrace , soaptoolkit+traceutility. For your scenario, if you want to
programmatically capture the message and log it, you can consider using
soapExtension as Ron suggested. Soap Extension can be used at both
clientside and server-side of webservice. Here are some reference articles
you can have a look.

#Fun with SOAP Extensions
http://msdn2.microsoft.com/en-us/library/ms972353.aspx

#Using SOAP Extensions in ASP.NET
http://msdn.microsoft.com/msdnmag/is...n/default.aspx

#How to: Implement a SOAP Extension
http://msdn2.microsoft.com/en-us/library/7w06t139.aspx

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.


Jan 12 '07 #7
Hello Tom,

Of course, soap extension can be applied on both sides(client and server)
of .NET implemented webservice. For client-side proxy, you also have two
means to apply a soapextension on it:

** through application's App.config file
** directly add soapextension attribute on a certain webmethod in the
generated proxy code file

Here are some web article and former thread discussing on this:

http://blogs.infosupport.com/marcelv...7/05/8615.aspx

http://www.thescripts.com/forum/thread427659.html

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 15 '07 #8
Steven,

Thanks for tolerating my lack of understanding. I followed your
instructions in the http://www.thescripts.com/forum/thread427659.html and
was able to get TraceExtension to write the SoapRequest and SoapResponse to
a file in my application.

I want to capture the raw XML especially from the SoapResponse and save it
in a table in a SQL Server database. Since the soap extension runs as part
of the proxy, how can I access the XML in TraceExtension from my client app
rather than saving it to a file?

Thanks again,
Tom

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:qK**************@TK2MSFTNGHUB02.phx.gbl...
Hello Tom,

Of course, soap extension can be applied on both sides(client and server)
of .NET implemented webservice. For client-side proxy, you also have two
means to apply a soapextension on it:

** through application's App.config file
** directly add soapextension attribute on a certain webmethod in the
generated proxy code file

Here are some web article and former thread discussing on this:

http://blogs.infosupport.com/marcelv...7/05/8615.aspx

http://www.thescripts.com/forum/thread427659.html

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 15 '07 #9
Thanks for the reply Tom,

As for the SoapExtension, though it is applied on our webservice webmethod
or client proxy's webmethod, the execution of the extension is separated
from our client application(who call the webservice proxy)'s code.
Therefore, there is no directly channel for us to control or access the
soapextension intances in client application's code(or from proxy). Do you
think it is possible that you directly add the code in soapextension to
store the response SOAP XML message into database? You can put the database
connection info in the soapextension attribute so that you can flexiblly
configure it through soapextension attribute or in app.config file.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 16 '07 #10
Steven,

Because of the separation, the SoapExtension does not know the entity the
XML is for so it couldn't save it properly. Besides, the table column where
the XML needs to be saved is part of the record that is populated by the web
service object.

Tom

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:VU**************@TK2MSFTNGHUB02.phx.gbl...
Thanks for the reply Tom,

As for the SoapExtension, though it is applied on our webservice webmethod
or client proxy's webmethod, the execution of the extension is separated
from our client application(who call the webservice proxy)'s code.
Therefore, there is no directly channel for us to control or access the
soapextension intances in client application's code(or from proxy). Do you
think it is possible that you directly add the code in soapextension to
store the response SOAP XML message into database? You can put the
database
connection info in the soapextension attribute so that you can flexiblly
configure it through soapextension attribute or in app.config file.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 16 '07 #11
Steven,

I added two static string properties to the SoapExtension, one for the
SoapRequest and the other for the SoapResponse. I set these properties in
the SoapMessage Stages AfterSerialize and BeforeDeserialization. When I
return from a call to a web service method, I access these properties to get
the XML.

Seems to work.

Tom

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:VU**************@TK2MSFTNGHUB02.phx.gbl...
Thanks for the reply Tom,

As for the SoapExtension, though it is applied on our webservice webmethod
or client proxy's webmethod, the execution of the extension is separated
from our client application(who call the webservice proxy)'s code.
Therefore, there is no directly channel for us to control or access the
soapextension intances in client application's code(or from proxy). Do you
think it is possible that you directly add the code in soapextension to
store the response SOAP XML message into database? You can put the
database
connection info in the soapextension attribute so that you can flexiblly
configure it through soapextension attribute or in app.config file.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 16 '07 #12
Thanks for your reply Tom,

As for the "static variable on SoapExtension class" approach you mentioned,
it does be a possible approach. However, there is a potential problem with
this approach. That's the concurrent access/thread safety of these static
members when there're multiple threads call the webservice proxy methods.

If your scenario does care on the above issue(client application may have
multiple threads calling the webservice proxy methods), you can consider
adding some additional thread-safe protection for your static variables on
the SoapExtension class. For example, you can use the "CallContext"
class's storage to store call-context specific data:

=================
public static string CurrentData
{
get
{
return CallContext.GetData("logdata") as string;
}
set
{
CallContext.SetData("logdata", value);
}
}
=====================

This can help prevent concurrent access on your webservice proxy.

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 17 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by William Ortenberg | last post: by
5 posts views Thread by TerryWilson | last post: by
4 posts views Thread by Bill Manring | last post: by
6 posts views Thread by k.vanderstarren | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.