Solved

consume asp.net wcf by jquery ajax

Posted on 2015-01-13
3
512 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
  • 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
 

Author Comment

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

Author Comment

by:ITsolutionWizard
ID: 40550235
any updates?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now