views:

211

answers:

3

What is the best way to generate soap xml in c#? I prefer to use xml-serialization if possible. Also, I need to add some custom attributes to the soap header, so not sure if this complicates things.

One more note: I'm connecting to a soap server on a linux server over TCP - the soap server was built in C++.

Also, the soap server does not respond to wsdl requests - it's fully locked down. Security is extremely tight where I work... :)

A: 

What are you trying to do? Call a webservice??

Use WCF and "Add Service Reference" in Visual Studio - and you're done!

No need to painstakingly, manually construct any SOAP messages - let WCF handle all the gooey stuff for you and concentrate on your actual business!

See msdn.microsoft.com/WCF for a great intro site and lots of article and videos and stuff.

And yes - using WCF does allow you to use XML serialization if you insist - but the native WCF DataContractSerializer might be an even better choice (approx. 10% faster than XML serialization, in most cases).

marc_s
@marc, I'm trying to call a linux-based soap server (C++, TCP). Is there a facile approach similar to WCF (man, I really miss WCF)?
code4life
So do you have a URL you can call? Try calling it using `?WSDL` at the end - if you get a WSDL displayed in a browser window, you can connect your WCF service to that URL, too - shouldn't be a problem, really.
marc_s
No, the soap server doesn't support the wsdl query. In fact it doesn't support any http:// calls at all... only listens on the tcp port.
code4life
A: 

The best way would be to use "Add Service Reference" and point to the WSDL of the service, either on disk or on the net. Then call the service through the generated proxy class.

See "How to Consume a Web Service".

John Saunders
@John, thanks, but how about if I need to serialize the class for communication with a soap server? Sorry for not being clear in my original question...!
code4life
@code4life: did you read the article at the link I posted? That's _how_ you call a SOAP server. It doesn't have to be another WCF server. WCF is interoperable. Just follow those directions and see what happens.
John Saunders
@John, I'm more interested in how to *generate* the soap message. The actual communication itself is being handled via standard frameworks here at the client site - I don't have control over the communication layer. I think you're idea of letting the proxy class get generated via wsdl would have been a great idea, by the way - except that the soap server is tcp-based and does not honor wsdl queries (e.g., mysoapserver?wsdl).
code4life
@code4Life: it doesn't _have_ to handle such queries. They should just send you the WSDL file. Do the "Add Service Reference" and type in the path to the WSDL file on disk.
John Saunders
@John, I tried to add the service reference, but that does not work. The path to the WSDL doesn't work - there is no WSDL support from the soap server. It turns out the server sends and receives SOAP messages, but does not provide WSDL support.
code4life
@code4life: Don't ask the server - ask the people who _wrote_ the server to give you the file. It's not a web service if there is no WSDL.
John Saunders
@John, it's not a web service - it's a soap server which was build using g++ on a linux box. In fact, it doesn't work over HTTP at all, only TCP is supported. That said, I do have the XSD - but no WSDL.
code4life
Then you're going to have to guess. Without a WSDL, you don't know if the server uses RPC/Encoded or Document/Literal, or what.
John Saunders
+2  A: 

If you have an XSD, take a look at WSCF.blue.

This article should introduce the concept behind it. You may need to generate some of the service definition yourself, but it should make building WCF contracts and a client proxy a lot easier than coding the SOAP messages by hand.

Programming Hero
I definitely like the idea described in the site. Not sure it will solve my needs right now, but this is the direction I'd like to take!
code4life