开发者

WCF Configuration for Endpoint in Another Project

开发者 https://www.devze.com 2023-03-20 19:38 出处:网络
I have two projects in a single solution. One project, let\'s call it MainProject, becomes an executable. The other project, let\'s call it ControlsProject, contains UserControl\'s and is referenced (

I have two projects in a single solution. One project, let's call it MainProject, becomes an executable. The other project, let's call it ControlsProject, contains UserControl's and is referenced (and used) within the MainProject. The ControlsProject also has a WCF Service Reference.

I have a two questions regarding this configuration:

  1. Can I just copy the WCF configuration from the ControlsProject to the MainProject (which I don't believe I can per " How to include Web reference endpoint configuration in another project ")
  2. In the ControlsProject configuration, the contract doesn't have a fully qualified namespace but rather a name such as 'ServiceName.IServiceInterfaceName'. What should the contract name be since the ControlsProject output will be a file located in the bin folder of the MainProject?

I've tried just copying the configuration over, but received the exception: "Could not find default endpoint element that references contract 'MyService.IMyService' 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 copied over the configuration, I fully qualified the name of the interface as ControlsProject.MyService.IMyService.

Any help you can provide is appreciated!

UPDATE (7/14/2011 5:28pm EST)

Here is the snippet from my client app.config:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IStatService" 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 clientCre开发者_高级运维dentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://intranet/StatService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStatService"
            contract="StatService.IStatService" name="BasicHttpBinding_IStatService" />
    </client>
</system.serviceModel>

Here is the snippet from my web service web.config:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>


Anytime you see the "Could not find default endpoint element for such and such contract" then your actual contract (the interface) is not referenced correctly in the app.config file. Go to the interface contract in the controls project double check the namespace it's in, you need that exact namespace."Interface name" as the contract element in the app.config. You also need to make sure your service name=Namespace.MyService is the correct namespace and class. One short way to know if you're right (this is only if you have resharper), in the appconfig where you declare service name= put the cursor over the service name and namespace and hit F12, if it doesn't take you anywhere you're referencing a namespace and class that don't exist, same goes for the contract=, if you F12 on that contract and it doesn't take you there, it's not referenced correctly (possibly misspelled).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号