0

I have a WCF project (:53763/WCFTestService.svc) and a web application(:50238/CSharp/test.aspx) in C#. I am trying to call the WCF project method in my web application. I have added the WCF project as a service reference in web application.

in test.aspx.cs file I have a method as follows

[WebMethod()]
    public static string GetWCF()
    {
        WCFTestServiceClient client = new WCFTestServiceClient();
        string result = client.XMLData("1122");
        return result;
    }

When I run this getting error :

Could not find default endpoint element that references contract 'TestWCFServiceReference.IWCFTestService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element

.

When I add the WCF project as a service reference in my web application, the web.config file in the web application is not updated automatically. (No code is added by default at the time of adding reference). Do I need to add anything in the web.config file for making it working?

web.config of WCF project is:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>

    <services>
      <service name="WCFTestService.RestService" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="WCFTestService.IRestService" behaviorConfiguration="web">          
        </endpoint>
      </service>      
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
        <!--<behavior>
          --><!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --><!--
          <serviceMetadata httpGetEnabled="true"/>
          --><!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --><!--
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>-->
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>
Sudha
  • 2,078
  • 6
  • 28
  • 53
  • Can you share config of your WCF service ? – Sandeep Kumar May 10 '13 at 10:56
  • Ok.. I have added the web.config file of my WCF project. – Sudha May 10 '13 at 12:32
  • In your configuration file you have only one endpoint with webHttpBinding that is used for restful address. So you can refer [here](http://sandeepkumar1234.blogspot.in/2013/04/how-to-test-restful-service.html) to configure and test restful service. – Sandeep Kumar May 11 '13 at 13:02
  • In your configuration file you have only one endpoint with webHttpBinding that is used for restful address. So you can refer [here](http://sandeepkumar1234.blogspot.in/2013/04/how-to-test-restful-service.html) to configure and test restful service. or add another endpoint to provide service metadata for SOAP client e.g. – Sandeep Kumar May 11 '13 at 13:08

2 Answers2

0

It sounds like there's an error you're going to need to resolve when you reference your WCF project. Look on your information tab (not warning/errors) on Visual Studio when you add the reference and you'll see the errors. I'm guessing it'll have something to do with Newtonsoft.Json - which there are many posts about, such as Error adding service reference: Type is a recursive collection data contract which is not supported

Community
  • 1
  • 1
Chris Dixon
  • 9,147
  • 5
  • 36
  • 68
0

In your configuration file you have only one endpoint with webHttpBinding that is used for restful address. So you can refer here to configure and test restful service. or add another endpoint to provide service metadata for SOAP client e.g.

     <endpoint address="" binding="basicHttpBinding" contract="WCFTestService.IRestService"                      bindingNamespace="">
          </endpoint>
Sandeep Kumar
  • 783
  • 1
  • 5
  • 13