Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have tried days to solve this damn error. I am calling the same service in asp.net and it works fine, but when I call it in a sharepoint solution it does not work. This is the error that I receive.

Server Error in '/' Application.
--------------------------------------------------------------------------------

Could not find endpoint element with name 'WSHttpBinding_IService1' and contract 'Service1.IService1' 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 name could be found in the client element. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Could not find endpoint element with name 'WSHttpBinding_IService1' and contract 'Service1.IService1' 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 name could be found in the client element.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

this is my app.config in the library:

 <system.serviceModel>
    <services>
      <service name="HelloWorldService2.Service1"
               behaviorConfiguration="HelloWorldService2.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/HelloWorldService2/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address=""  binding="wsHttpBinding"
                  contract="HelloWorldService2.IService1">
         <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding"
                  contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="HelloWorldService2.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>

          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

this is code in web.config where the .svc file is located.

  <system.serviceModel>
    <services>
      <service name="HelloWorldService2.Service1"
               behaviorConfiguration="HelloWorldService2.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/HelloWorldService2/Service1/" />
          </baseAddresses>
        </host>
      <endpoint address=""  binding="wsHttpBinding"
                  contract="HelloWorldService2.IService1">
         <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
         <endpoint address="mex" binding="mexHttpBinding"
                  contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="HelloWorldService2.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
           <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

this is the code that I use in the app.config file of the sharepoint visual web part project:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:62954/TestSayHello/Service.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="Service1.IService1" name="WSHttpBinding_IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

this is the code that I use in code behind in both sharepoint visual web part and in asp.net web page. The strange thing is that it works fine in asp.net but not in sharepoint. A couple of days ago I was testing almost the same thing, and somehow it was working in sharepoint, but then suddenly it stopped working. From that day on I have been trying and trying but could not solve it. I tried to simply the code and tried this code but I am still stuck.

Please help!!

 protected void Page_Load(object sender, EventArgs e)
    {
        Service1Client client = new Service1Client("WSHttpBinding_IService1");
        Response.Write(client.SayHello("Helm"));

        GridView1.DataSource = client.ListCustomers();
        GridView1.DataBind();

    }
share|improve this question
    
Have you tried putting the web service configuration (Service.ServiceModel tag) in the SharePoint's web.config? –  Hossein Aarabi Mar 26 '13 at 20:03
    
you don't mean system.serviceModel, right? –  Helm Ifort Mar 26 '13 at 20:13
1  
I mean <System.serviceModel>...</System.serviceModel>. Copy that section and place it in your main SharePoint web.config file (in IIS, find your SharePoint virtual directory, there is a webconfig; make sure you save a copy before you edit). Your code is trying to find an endpoint for your WCF service; it cannot find it, because you have not specified an endpoint in your SP web.config. –  Hossein Aarabi Mar 27 '13 at 16:52
    
Hi Hossein, I will give it a try. Let you know as soon as possible. –  Helm Ifort Mar 29 '13 at 8:13

1 Answer 1

make sure you follow this msdn tutorial, its long winded but looks like your missing some nodes within your xml in web.config ;)

http://msdn.microsoft.com/en-us/library/ff648431.aspx

EDIT

done some digging for you ;) , iv found this on the site:

"This error can arise if you are calling the service in a class library and calling the class library from another project."

In this case you will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app. This is the way to go even with PRISM and WPF/Silverlight.

http://stackoverflow.com/questions/352654/could-not-find-default-endpoint-element

so as noted above you have put in the settings within the web.config of the web application (web site) but it looks like you need to add it in the project app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="myclassThathaswebservice.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <myclassThathaswebservice.Properties.Settings>
            <setting name="C_ServicesDev" serializeAs="String">
                <value>http://demoservices:101/myServices2010/workflow.asmx</value>
            </setting>
            <setting name="C_ServicesInt" serializeAs="String">
                <value>http://mywebservices2010:101/myServices2010/workflow.asmx</value>
            </setting>
            <setting name="C_ServicesLive" serializeAs="String">
                <value>http://mylivewebservices2010:101/myServices2010/workflow.asmx</value>
            </setting>
        </myclassThathaswebservice.Properties.Settings>
    </applicationSettings>
</configuration>

also another issue very similar if not the same to yours

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4d907941-3b27-4208-91f3-12b277968975/

share|improve this answer
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  Mike Mar 26 '13 at 21:57
    
@mike yes i understnad that and i usualy do provide the answer on this site and reference to the link! the issue is its so big hence why i didnt post it but only the url ;) –  ali Sharepoint Mar 27 '13 at 9:04
    
Thank you both of you for trying to help. Ali, you don't have to put all the text that is found in the link, but a suggestion would be nice. Still, thanks for helping. I appreciate it. –  Helm Ifort Mar 27 '13 at 9:12
    
I still have not found the issue that is causing the error above. Please any who can help figure out why sharepoint does not find the service. –  Helm Ifort Mar 27 '13 at 14:09
    
just ammended my answer, please check the edit ;) , in my project app.config those settings you can see are the same that you see in the web.config –  ali Sharepoint Mar 27 '13 at 14:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.