Solved

consume asp.net wcf by jquery ajax

Posted on 2015-01-13
3
695 Views
Last Modified: 2015-01-16
I have below codes create wcf and consume wcf by jquery ajax.
And you can take a look of attached document for error.
One screen showing I use wcf utility to check the service is actually working fine.
second image shown error message. and I don't know why it happens.

Can you help me? Take a look of the code consuming side and see anything wrong?

Thanks,

12<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
      <script type="text/javascript">
          // Urls to access the WCF Rest service methods
           $(document).ready(function () {
              $.ajax({
                  type: "GET",
                  dataType: "json",
                  contentType: "application/json; charset=utf-8",
                  processData: true,
                  url: "http://localhost:62937/ServiceJVC.svc?wsdl/NetPrice/",
                  data: JSON.stringify({ "companyNo":"062", "customerNo": "337557", "modelList":"KDAV300,KDX40,CSGW1200", "qtyList":"10,1,5", "orderDateTime":"11/07/2014", "repNo": "SA7" }),
                  success: function (data, status, jqXHR) {
                      //alert("success" + data);
                      alert("success");
                  },
                  error: function (xhr) {
                      alert(xhr.responseText);
                      alert("Error");
                  }
 
 
              });
          });
 
       
    </script>
 
 
 
    [ServiceContract]
    public interface IServiceJVC
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "NetPrice/{companyNo}/{customerNo}/{modelList}/{qtyList}/{orderdateTime}/{repNo}")]
        string NetPrice(string companyNo, string customerNo, string modelList, string qtyList, string orderDateTime, string repNo);
    }
0
Comment
Question by:ITsolutionWizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40548601
Hi,
from what I can see from your implementation, you have a RESTfull service. Therefore your service call from jQuery needs to set the parameters inside the url and not inside the message as JSON.

Alternative 1:
Adjust the jQuery AJAX url and pass the parameters inside the url

Alternative 2:
Change your webservice to a dedicated service which expects the parameter inside the call as JSON data

HTH
Rainer
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40548909
I don't quite understood what you mean. Can you show me in codes? Thanks
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40550235
any updates?
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question