Question

i need to visit a secure web service, every request in the header need to carry a token.

i know the endpoint to the web service, i also know how to create the token.

but i cannot see the WSDL for the webservice.

is there a way in C#, to create a soap client, without the WSDL file.

Was it helpful?

Solution

I have verified that this code, which uses the HttpWebRequest class, works:

// Takes an input of the SOAP service URL (url) and the XML to be sent to the
// service (xml).  
public void PostXml(string url, string xml) 
{
    byte[] bytes = Encoding.UTF8.GetBytes(xml);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    request.ContentLength = bytes.Length;
    request.ContentType = "text/xml";

    using (Stream requestStream = request.GetRequestStream())
    {
       requestStream.Write(bytes, 0, bytes.Length);
    }

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        if (response.StatusCode != HttpStatusCode.OK)
        {
            string message = String.Format("POST failed with HTTP {0}", 
                                           response.StatusCode);
            throw new ApplicationException(message);
        }
    }
}

You will need to create the proper SOAP envelope and pass that in as the "xml" variable. It takes some reading. I found this SOAP Tutorial to be helpful.

OTHER TIPS

A SOAP client is simply an HTTP client with more stuff in it. See the HttpWebRequest class. You'll then have to create your own SOAP message, perhaps using XML Serialization.

You could create your own service, expose it to have a WSDL and then generate the client from that... kind of the long way.

Can you ask the developers of the web service to send you the WSDL and XSD file(s) by email? If so, you can dump the files in a folder and then add a Service Reference using the WSDL on your hard disk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top