How to create a soap client without WSDL

I need to visit a secure web service, each request in the header should carry a token.

I know the endpoint of the web service, I also know how to create a token.

but I do not see the WSDL for the web service.

is there any way in C # to create a client client without a WSDL file.

+6
c # web-services header ws-security token
source share
4 answers

I checked that this code that 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 correct SOAP envelope and pass it as the "xml" variable. This requires some reading. I found this SOAP Tutorial useful.

+5
source share

The SOAP client is just an HTTP client with lots of stuff. See the HttpWebRequest class . Then you need to create your own SOAP message, possibly using XML serialization.

+3
source share

You can create your own service, put it on WSDL, and then generate the client from this ... long way.

0
source share

Can you ask the web service developers to email you the WSDL and XSD files? If so, you can reset the files in the folder, and then add the service link using WSDL on your hard drive.

0
source share

All Articles