0

What is the easiest way to create a web service with XML response?

  1. Use WCF to create the web service? (seems really complicated)
  2. If i want to use WCF to create my web service, where do I start?
001
  • 62,807
  • 94
  • 230
  • 350
  • 1
    I think if you dig into WCF REST solutions, you won't find generating XML complicated. I found the book RESTful .NET very helpful as well. http://www.amazon.com/RESTful-NET-Build-Consume-Services/dp/0596519206/ref=sr_1_cc_2?ie=UTF8&qid=1286189339&sr=1-2-catcorr – kenny Oct 04 '10 at 10:50

4 Answers4

0

The easiest way to create a web service with an XML response is, no kidding, to put an XML file on a standard web server and serve it as a static file.

I'm guessing you want something more flexible than that, though...

You've got several options, and WCF is at the more complex (but flexible) end of the spectrum. First question: what's your client? Are you writing it? Do you want to write a web service that can be consumed by other clients?

Do you want to use REST -- i.e. plain-old-XML (POX) over plain-old-HTTP? XML-RPC? SOAP?

WCF supports all of these, so this really depends on which clients you want to support.

Update: If you want to support XML-RPC, you could do worse than start with this implementation of XML-RPC for WCF by Clemens Vasters. I asked a question about this here.

Community
  • 1
  • 1
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • I understand that WCF supports all of these, and its flexible, but its very complicated, alot more complicated than simply creating a SOAP web service. – 001 Oct 04 '10 at 10:48
  • I just want to create a XML-RPC web service, no SOAP (it has too much overhead). – 001 Oct 04 '10 at 10:49
0

In your case, I would definitely use WCF with the REST binding (webHttpBinding) - and I would disagree about it being complicated to learn.

Check out these resources to get started:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
0

I just made a web service.

PHP server side code:

<?php // instantiate SOAP server
function sendXmlMsg($msg){
return $msg;
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSD
$server = new SoapServer("mark.wsdl");
// Register exposed method
$server->addFunction('sendXmlMsg'); // generate captcha
//$server->addFunction('check_captcha'); // check captcha ID
$server->handle(); //?>

My WSDL file is

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Msg91'
  targetNamespace='http://localhost/webtest/test.wsdl'
  xmlns:tns='http://localhost/webtest/test.wsdl'
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  xmlns='http://schemas.xmlsoap.org/wsdl/'>

   
 
<message name='sendXmlMsgRequest'>
  <part name='msg' type='xsd:string'/>
</message>
<message name='sendXmlMsgResponse'>
  <part name='Result' type='xsd:string'/>
</message>
<portType name='Msg91PortType'>
  <operation name='sendXmlMsg'>
    <input message='tns:sendXmlMsgRequest'/>
    <output message='tns:sendXmlMsgResponse'/>
  </operation>
</portType>

<binding name='Msg91Binding' type='tns:Msg91PortType'>
  <soap:binding style='rpc'
    transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='sendXmlMsg'>
    <soap:operation soapAction='urn:xmethods-delayed-quotes#sendXmlMsg'/>
    <input>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </input>
    <output>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </output>
  </operation>
</binding>

<service name='Msg91Service'>
  <port name='Msg91Port' binding='tns:Msg91Binding'>
    <soap:address location='http://localhost/webtest/test.php'/>
  </port>
</service>
</definitions>

Client side PHP file:

<?php
$client = new SoapClient("mark.wsdl");
$params= array('HiT');
echo $client->__soapCall( 'sendXmlMsg', $params );
?>
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Saki Make
  • 259
  • 1
  • 6
  • 16
0

It's actually pretty easy to create a WCF service. There are plenty of tutorials online.

As for returning xml, there are a few ways. You can do this with an 'old school' SOAP web service by converting the xml to a string in the service and then convert back in the client. It's not pretty but it works.

An alternative, and the way I'd do it, would be to use WCF and create a data contract that maps your xml.

You can do some pretty good stuff with data contracts, like pass round datasets and custom types but this can sometimes limit the binding types you can use.

TeamWild
  • 2,460
  • 8
  • 43
  • 53