Endpoint not found - WCF web service

79,132

I have created a similar service as the one that you have according to this:

 [ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(UriTemplate="/CallADSWebMethod", Method="POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
    string CallADSWebMethod(string vin, string styleID);
}

The important thing that I added was the UriTemplate part that tells the service how the call should look like. I then implemented this service as:

public class Service : IService
{
    public string CallADSWebMethod(string vin, string styleID)
    {
        return vin + styleID;
    }
}

and in my web.config I have the following:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="Description7aBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="asmx" name="WebApplication1.Service">
    <endpoint address="basic" binding="basicHttpBinding" name="httpEndPoint" contract="WebApplication1.IService"/>
    <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="webBehavior" name="webEndPoint" contract="WebApplication1.IService"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<behaviors>
    <endpointBehaviors>
        <behavior name="webBehavior">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior name="asmx">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

I have then created a simple page that looks like this that calls this service using jQuery:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Ok").click(function () {
                var jData = {};
                jData.vin = "one";
                jData.styleID = "test";
                $.ajax({
                    type: "POST",
                    url: "/Service.svc/json/CallADSWebMethod",
                    data: JSON.stringify(jData),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert(msg);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" id="Ok" name="Ok" value="Ok" />
    </div>
    </form>
</body>
</html>

and this produces a alert with the text onetest. Hope this can give som guidance.

Share:
79,132

Related videos on Youtube

James
Author by

James

Updated on July 20, 2022

Comments

  • James
    James almost 2 years

    I have created 2 endpoints for my WCF service.

    It is working fine with basicHttpBinding but causes error for webHttpBinding.

    Error = Endpoint not found.

    Operation contract definition

    [OperationContract]
    [WebInvoke(Method = "POST",
               BodyStyle = WebMessageBodyStyle.WrappedRequest,
               ResponseFormat = WebMessageFormat.Json)]
    VINDescription CallADSWebMethod(string vin, string styleID);
    

    web.config:

    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="Description7aBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                <message clientCredentialType="UserName" algorithmSuite="Default"/>
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://services.chromedata.com:80/Description/7a"
                    binding="basicHttpBinding"
                    bindingConfiguration="Description7aBinding"
                    contract="description7a.Description7aPortType"
                    name="Description7aPort"/>
        </client>
        <services>
          <service behaviorConfiguration="asmx" name="ADSChromeVINDecoder.Service">
            <endpoint name="httpEndPoint" 
                      address="" 
                      binding="basicHttpBinding"
                      contract="ADSChromeVINDecoder.IService"/>
            <endpoint name="webEndPoint"
                      address="json"
                      behaviorConfiguration="web"
                      binding="webHttpBinding"
                      contract="ADSChromeVINDecoder.IService"/>
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp/>
              <enableWebScript/>
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="asmx">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
    

    Please suggest me how I can fix this?

    • carlosfigueira
      carlosfigueira over 11 years
      How are you getting the "Endpoint not found" error? Sending a request to which address?
  • James
    James over 11 years
    It is working now..I noticed 3 things here : 1 : UriTemplate="/CallADSWebMethod" 2 : Adding binding = "mexHttpBinding" 3 : data: JSON.stringify(jData), Which I was not doing. Can you please add some light on these.
  • Johan Lundqvist
    Johan Lundqvist over 11 years
    1. The UriTemplate just maps a URI or a set of URIs to a service operation, i e how the service can be called. 2. This binding just adds the possibility to access the WSDL. 3. That is a function for making an object into a json string suitable for use in an ajax call, just a shortcut, you could do this yourself but it is handy.
  • James
    James over 11 years
    Does this make the processing faster if I JSON.stringify the response coming from the call too?
  • Johan Lundqvist
    Johan Lundqvist over 11 years
    The processing will not be faster, and since you are getting a json string back you can't use JSON.stringify, you can use JSON.parse(jsontext) in that case.
  • James
    James over 11 years
    Currently it is working fine..Is there any benefit of using JSON.parse in anyways.
  • James
    James over 11 years
    It is all working now..But all of a sudden I am getting this error for - JSON.stringify() -- AS JSON is undefined..It is coming only for IE all version...Can you shed some light on it.
  • Johan Lundqvist
    Johan Lundqvist over 11 years
  • James
    James over 11 years
    I tested in IE8 and 9 but error was there..So what I did was, I made the string in JSON format by myself rather than using the function..ann I was saved..