2

I'm trying to call a WCF Webservice, from a dll I have made, running inside our CAD Software. I cannot get it to work though.

When I try to establish my proxy, I get the following error:

Could not find endpoint element with name 'BasicHttpBinding_IAxaptaService' and contract 'AxaptaProxy.IAxaptaService' 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.

I have searched around abit, and I assume the problem is due to my DLL running inside another program. There was some articles about copying EndPoint configuration from the app, to the service, but I didn't quite catch, what I was supposed to do.

Anyone have an idea, as to how I can make this work?

The App.Config, created by my client is this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IAxaptaService" 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://localhost:4726/LM/AxaptaService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAxaptaService"
                contract="AxaptaProxy.IAxaptaService" name="BasicHttpBinding_IAxaptaService" />
        </client>
    </system.serviceModel>
</configuration>

I have tried to merge this into my web.config, on the site that hosts the web-service, as this:

  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="GetStream.customBinding0">
          <binaryMessageEncoding/>
          <httpTransport/>
        </binding>
      </customBinding>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IAxaptaService" 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>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AutoCompletionAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="AutoCompletion">
        <endpoint address="" behaviorConfiguration="AutoCompletionAspNetAjaxBehavior" binding="webHttpBinding" contract="AutoCompletion"/>
      </service>
      <service name="GetStream">
        <endpoint address="" binding="customBinding" bindingConfiguration="GetStream.customBinding0" contract="GetStream"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <client>
      <endpoint address="http://localhost:4726/LM/AxaptaService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAxaptaService"
          contract="AxaptaProxy.IAxaptaService" name="BasicHttpBinding_IAxaptaService" />
    </client>
  </system.serviceModel>

There are a couple of other stuff in there already. I can remove them, if that makes it easier. I've left them in, incase they have some influence on it.

So I tested the service, from a stand-alone winform application, and it works fine. Could it be because of the App.config? Does my config get loaded, for the .dll?

Nicolai
  • 2,835
  • 7
  • 42
  • 52
  • if your application is called myapp.exe, you'll need to copy it to myapp.exe.config – PeskyGnat Nov 07 '11 at 12:47
  • @Nicolai: That basically looks right. Where is the service you're trying to connect to? The same box? Or a different box? I'd be surprised if you were getting the same error after copying that config over, and would expect you'd be getting a different exception now - probably something about not being able to find the service. – Merlyn Morgan-Graham Nov 07 '11 at 13:36
  • Merlyn: Yea, right now it's all on my localhost, with VisualStudio's internal webserver. – Nicolai Nov 07 '11 at 13:37
  • I've tried to create a winform app, and add the service reference to that, and it worked fine. I'm guessing it's my .dll that has some issue then. – Nicolai Nov 07 '11 at 13:49

2 Answers2

4

You'll need to copy the connection information from MyDll.dll.config to Web.config.

Be careful to merge configuration sections rather that simply adding the new data side-by-side, or replacing it. If there are already sections with the same name, you will probably have to combine them.

Here's an article describing the guts of the WCF portions of app.config:

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

The main pieces are:

<system.serviceModel>
   <bindings>
     <!-- various bindings go here... -->
   </bindings>
   <client>
     <!-- endpoints go here... -->
   </client>
</system.serviceModel>

You'll need to combine everything within those nodes - add the various types of endpoint elements and the binding elements to your service's web.config.

So, if you have a config that looks like this:

<system.serviceModel>
   <bindings>
     <someBindingType name="someBinding" />
   </bindings>
   <client>
     <endPoint name="someEndpoint />
   </client>
</system.serviceModel>

You'll need to copy over the someBindingType and endPoint elements. The whole element, including ending tags (if there are any), and child elements.

Make sure you don't duplicate system.serviceModel, bindings or client elements. If they're already there, merge into them rather than creating new elements/duplicating.

Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183
  • I'm not entirely sure on how to do this. Is it the binding, or endpoint (or both)? Should I just merge it into the web.config? My webservice is running in an existing ASP.NET site. – Nicolai Nov 07 '11 at 12:41
  • @Nicolai: Oh, it is a web service. For some reason I thought you meant a Windows service. Yes, merge the data into `web.config` then. I've edited the answer to fix this. – Merlyn Morgan-Graham Nov 07 '11 at 12:42
  • I wish I understood this, but I apparently don't. I've copy/pasted the bindings, from App.config, into my web.config. What do I do with the client part? Do I just copy the whole Client node, into my web.config? I tried to paste the content, into a new Service node, in web.config, but that didn't seem to do anything good. – Nicolai Nov 07 '11 at 13:17
  • @Nicolai: For each element under binding, copy. For each element under client, copy. This means you'll be copying stuff like `wsHttpBinding` and stuff like `endpoint`. You'll want to copy the entirety of each binding and endpoint element, instead of just part of each element. If it turns out more than one have the same name, though, you'll have a conflict. If that ends up being the case, paste some of your config files into your question. – Merlyn Morgan-Graham Nov 07 '11 at 13:20
  • @Nicolai: "new service node" - make sure you don't have two `system.serviceModel` nodes, two `bindings` nodes, or two `client` nodes. If those nodes are already there you'll have to merge them. – Merlyn Morgan-Graham Nov 07 '11 at 13:21
2

I finally got it to work!

The problem was, that the app.config does not get loaded, in my .dll project. To fix this, I created the binding, in code, instead of through the app.config, as mentioned in this thread: WCF Configuration without a config file

Thank you for all the help though. Merlyn, without your help, I wouldn't even have gotten this far.

Community
  • 1
  • 1
Nicolai
  • 2,835
  • 7
  • 42
  • 52