Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net - Consuming webservice without WSDL

We have a new accounting system that provides webservice interface to external clients. I want to access one of the interfaces but there's no WSDL so i created the request through the use of HttpWebRequest and it works fine.

However to ease the creation of the requests and parsing of the response i would like to create some kind of automapping function. I have the request and response structure in an XSD file. Any ideas?

Request creation:

public void SendRequest()
{
    HttpWebRequest request = CreateWebRequest();
    XmlDocument soapEnvelopeXml = new XmlDocument();
    soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
        <soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
        <soap:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">

            ++ structure type inserted here ++   

        </soap:Body>
        </soap:Envelope>");

    using (Stream stream = request.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }

    using (WebResponse response = request.GetResponse())
    {
        using (StreamReader rd = new StreamReader(response.GetResponseStream()))
        {
            string soapResult = rd.ReadToEnd();
            Console.WriteLine(soapResult);
        }
    }
}
like image 787
Sys Avatar asked May 23 '11 11:05

Sys


People also ask

Can we call SOAP service without WSDL?

Without the WSDL, it will be responsibility of the developer to know the definition of the SOAP Web Service to consume . SOAP envelope, SOAP Body and the complete XML request has to be built by the developer and pass it to the Http client.

Is WSDL mandatory for SOAP?

The WSDL Generator component is not essential for using SOAP. Administrators can still write service calls to Content Server in SOAP if needed. The WSDL Generator provides flexibility in altering existing client applications.

Do I need a WSDL?

A WSDL document is used to describe a web service. This description is required, so that client applications are able to understand what the web service actually does. The methods which are exposed by the web service.


1 Answers

Well, if you really have no way of getting hold of a proper WSDL file but have XSD:s you could probably use the xsd.exe tool to create classes that map to your request and response types.

Something like this (run this in a Visual Studio Command Prompt)

xsd.exe TheRequest.xsd /c /n:Your.Namespace
xsd.exe TheResponse.xsd /c /n:Your.Namespace

But really, try your best to find that WSDL, it will make your life a lot easier..

like image 200
CodingInsomnia Avatar answered Nov 15 '22 13:11

CodingInsomnia