locked
Error: Could not find default endpoint element that references contract 'DServices.IDServices' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element RRS feed

  • Question

  • User1462899359 posted

    Hello expertise.

    i have a service and website application. i have add reference in website application

    finally when i consume the service with this code = DServicesClient proxy = new DServicesClient();

    i am getting an error in wcf rest service. i have paste my code below..

    service

    ------------------

    namespace DoctorServices
    {
      
        [ServiceContract]
        public interface IDServices
        {
            [OperationContract]
            [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "XMLData/{id}")]
            string XMLData(string id);

            [OperationContract]
            [WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json ,
                BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="json/{id}")]
            string JSONData(string id);

            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "ValidUser/suser")]
            bool CheckValidUser(SUser suser);


        }
    }

    ----------------------------------------------

     public class DServices : BaseClass, IDServices
        {
            BOL_UserSecurity oBOL_UserSecurity;

            public string XMLData(string id)
            {
                return "Your Requested Product" + id;
            }

            public string JSONData(string id)
            {
                return "Your Requested Product" + id;
            }
      
            public bool CheckValidUser(SUser user)
            {
                oBOL_UserSecurity = new BOL_UserSecurity();
                 return oBOL_UserSecurity.CheckValidUser(user);

                }
                catch (Exception ex)
                {
                    throw;
                }

            }


        }

    ---------------------------

     
      <system.serviceModel>

        <services>

          <service name="DoctorServices.DServices" behaviorConfiguration="serviceBehavior">
            <endpoint address="" binding ="webHttpBinding" contract="DoctorServices.IDServices" behaviorConfiguration="web" ></endpoint>
            <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
            
          </service>

        </services>
        
        
          <behaviors>
          <serviceBehaviors>
            <behavior name="serviceBehavior">
             
              <serviceMetadata httpGetEnabled="true"/>
              
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>

            <endpointBehaviors>
              <behavior name="web">
                <webHttp/>
              </behavior>
              
            </endpointBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     
     
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
      </system.webServer>

    --------------------------------------

    finaly when add this service in Web application . when initialize this proxy getting error.

    DServicesClient proxy = new DServicesClient();

    string xml = proxy.XMLData("876");

    -------------------------

    please help me .. i m new in wcf

    Thursday, February 6, 2014 1:48 PM

Answers

  • User260886948 posted

    Hi,

    I saw that you were using the wcf rest service, then how did you get this:

    DServicesClient proxy = new DServicesClient();

    We can not use the add service references to gerente the proxy. One way to implement it is to use the ChannelFactory to call the wcf service, here is the example:
    http://msdn.microsoft.com/en-us/library/bb412178.aspx .

    And I saw that you have used the following:

    [WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json ,
                 BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="json/{id}")]
             string JSONData(string id);
    

    Then you can browser it in the IE with following uri, if the id="876":
    http://localhost:(yourportnumber)/DServices/json/876

    Best Regards,
    Amy Peng

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 11, 2014 4:57 AM