Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Do you hav any idea abt calling http(not https) web service(with username and password for authentication )* in asp.net.its not SOAP web service. Web service is devloped in java. So wsdl.exe won't work nither calling though reference.

this is the SOAP UI extracted SOAP envelop

HTML
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ak="http://linkaddress">
   <soapenv:header>
      <ak:password>?</ak:password>
      <ak:username>?</ak:username>
   </soapenv:header>
   <soapenv:body>
      <ak:vehicle>
         <chassisno>?</chassisno>
         <plateno>?</plateno>
         <platecode>?</platecode>
      </ak:vehicle>
   </soapenv:body>
</soapenv:envelope>
Posted
Updated 24-Oct-11 23:42pm
v2

If I am not misunderstood, You want to Call your HTTP based Java Web Service(Servlet) in Asp.Net.

This also means you are willing to call REST based Service.

Try as below code to call REST based Service in your Asp.Net code.
C#
string url = "YourWebServiceUrl";
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

if (response.StatusCode == System.Net.HttpStatusCode.OK)
 {
   System.IO.Stream receiveStream = response.GetResponseStream();
   System.IO.StreamReader readStream = null;

   if (response.CharacterSet == null)
    readStream = new System.IO.StreamReader(receiveStream);
   else
    readStream = new System.IO.StreamReader(receiveStream, 

    System.Text.Encoding.GetEncoding(response.CharacterSet));

    string result = readStream.ReadToEnd();
    response.Close();
    readStream.Close();
}

Have a look at below links for more information on REST.
https://www.ibm.com/developerworks/webservices/library/ws-restful/

http://www.infoq.com/minibooks/emag-03-2010-rest

Updated -

While calling REST Service, it also important to consider what kind of your Web-Method is - Get/Post(Not considering Put and Delete for now).

Have a look at below Article which elaborates Developing and Consuming REST Services.
Developing a REST Web Service using C# - A walkthrough

You may look at only "Part # 6 - Testing the application" section from above article to understand, How to Call Get/Post Web-Methods of REST Service.
 
Share this answer
 
v3
Comments
rajnish2patel 24-Oct-11 7:16am    
Thanks for the response. This is fine but
1. where to pass username and password as we do in SOAP header.
2. The services are authenticated through these username and password and how to call services them.
for you only i am improving my question .
RaisKazi 24-Oct-11 7:24am    
Are you trying to call Servlet(REST) based Service or SOAP based Service?
RaisKazi 24-Oct-11 7:42am    
Please refer my updated answer.
Yahoo Finally Solved

C#
string sResponse = string.Empty;
        try
        {
            Uri uri = new Uri(sFetchURL);
            if (uri.Scheme == Uri.UriSchemeHttp)
            {

                HttpWebRequest request = null;
                request = (HttpWebRequest)HttpWebRequest.Create(uri);


                request.Method = WebRequestMethods.Http.Get;
                request.ContentType = "text/xml;charset=\"utf-8\"";

                string strSOAPRequestBody = "" +
           "<soap-env:header xmlns:soap-env="#unknown">" +
            "<ak:password xmlns:ak="#unknown">" + myPassword + "</ak:password>" +
            "<ak:username xmlns:ak="#unknown">" + myUserName + "</ak:username>" +
            "</soap-env:header>" +
            "<soap-env:body xmlns:soap-env="#unknown">" +
                "<ak:vehicle xmlns:ak="#unknown">" +
                "<chassisno>" + sChessisNo + "</chassisno>" +
                "<plateno>" + sPlateNo + "</plateno>" +
                "<platecode>" + sPlateCode + "</platecode>" +
            "" +
            "</ak:vehicle></soap-env:body>" +
        "";


                request.Method = "POST";
                request.ContentType = "application/soap-xml; charset=UTF-8";
                request.Headers.Add("SOAPAction:\"\"");

                request.ContentLength = strSOAPRequestBody.Length;
                System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(
                                                        request.GetRequestStream());
                streamWriter.Write(strSOAPRequestBody);
                streamWriter.Close();
                System.IO.StreamReader streamReader = new System.IO.StreamReader(
                                                          request.GetResponse().GetResponseStream());
                while (!streamReader.EndOfStream)
                    sResponse += streamReader.ReadLine();
            }

        }
        catch (WebException err)
        {

            HttpWebResponse httpResponse = null;
            httpResponse = (HttpWebResponse)err.Response;
            Stream baseStream = httpResponse.GetResponseStream();

            System.IO.StreamReader streamReader2 = new System.IO.StreamReader(baseStream);
            while (!streamReader2.EndOfStream)

                sResponse += streamReader2.ReadLine();

        }

        return sResponse;
 
Share this answer
 
v4
Comments
RaisKazi 25-Oct-11 5:50am    
It's good to see, you finally resolved this. :)
rajnish2patel 25-Oct-11 6:23am    
Thx Sir
kiran dangar 25-Oct-11 7:04am    
Formatting issue!!!
RaisKazi 25-Oct-11 12:55pm    
Formatted using "<pre>" tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900