0

I want to invoke a service from javascript and then to display the response data in html file. Is it possible? Have anyone done this before? Any pointers or solution will be helpful. Thanks

Request Message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:log="http://login">
   <soapenv:Header/>
   <soapenv:Body>
      <log:validateLogin>
         <log:login>
            <log:password>password</log:password>
            <log:username>username</log:username>
         </log:login>
      </log:validateLogin>
   </soapenv:Body>
</soapenv:Envelope>

Response Message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <validateLoginResponse xmlns="http://login">
         <validateLoginReturn>true</validateLoginReturn>
      </validateLoginResponse>
   </soapenv:Body>
</soapenv:Envelope>

I need to create the request soap message, send it to service, and read the response.

4
  • 1
    is web service on different domain? Commented Mar 13, 2012 at 10:24
  • 1
    What kind of webservice? Rest-based services are no problem, when they support JSONP. Your main obstacle will be the same origin policy. Commented Mar 13, 2012 at 10:24
  • @GovindKamalaPrakashMalviya, Yes Webservice is on different domain, so looking to get thro' it Commented Mar 14, 2012 at 9:34
  • @Ahamed, you can'r call cross domain Ajax (only ajax is option to call any service from javascript), you can use only JSONP for cross domain, you have to use server side scripting for soap web services. Commented Mar 14, 2012 at 9:38

2 Answers 2

1

You can try

var id=1;
$.ajax({
    type: 'post',
    url: '../webservice.asmx/yourmethod',
    contentType: "application/json; charset=utf-8",
    data:{'id':id}
    dataType: "json",
    beforeSend: function () {
    //show wait
    },
    success: function (msg) {
        if (msg.d != null) {
        //result is obtained
        }
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Where do I have to send the request strings, say logon credentials?
@Amritpal Singh, I just tried as you mentioned, but getting javascript error as follows. XMLHttpRequest cannot load http://localhost:8080/Service/services/GreetingService/getWelcomeMessage. Origin null is not allowed by Access-Control-Allow-Origin. How to resolve this. I am doing for test service, which is hosted in localhost. Apache tomcat server 1.7.
I think you are trying cross domain webservice for that you just check the link simple-talk.com/dotnet/asp.net/…
1

see http://www.local-guru.net/blog/2010/1/24/calling-webservices-from-mootools-jquery-or-dojo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.