简体   繁体   中英

WCF - Client Endpoint Configuration Error

In my client application, I'm getting the following error:

Could not find endpoint element with name 'QueuedService' and contract
'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 name could be found in the client element.

I used svutil.exe to generate the client proxy I'm using. Typically I hand-roll my own proxy, and I notice the generated version of the interface for the service contract was not in the namespace I originally specified in the service contract:

// Auto-generated proxy

namespace MyServices.Contracts
{
    // Request object in correct namespace

    [System.Runtime.Serialization.DataContractAttribute(
        Name="MyRequest",
        Namespace="http://schemas.datacontract.org/2004/07/MyServices.Contracts")]
    public class MyRequest
    {
        // ...
    }
}

// Service contract NOT in namespace

[System.ServiceModel.ServiceContractAttribute(
    ConfigurationName="IMyService")]
public interface IMyService
{
    // ...
}

My host application web.config specifies the service endpoints (one for MSMQ and one for TCP):

<system.serviceModel>
<service>

<!-- etc... -->    

<endpoint name="QueuedService"
          address="net.msmq://localhost/private/MyQueue"
          binding="netMsmqBinding"
          bindingConfiguration="MsmqDefaultBinding_Local"
          contract="MyService.Contracts.IMyService" />
<endpoint name="TcpService"
          address="net.tcp://localhost/ServiceHost/TheService.svc"
          contract="MyServices.Contracts.IMyService"
          binding="netTcpBinding"
          bindingConfiguration="netTcpWindowsBinding" />
</service>
</system.serviceModel>

The client app is using the service like this:

var endpointConfigName = GetEndpointConfigNameFromConfig();

using(var myServiceClient = new MyServiceClient(endpointConfigName))
{
    // Create Request object...

    // Call service like so:

    myServiceClient.SomeServiceMethod(requestObject);
}

And the client's web.config:

<client>
    <endpoint name="QueuedService"
            address="net.msmq://localhost/private/MyQueue"
            binding="netMsmqBinding"
            bindingConfiguration="MsmqDefaultBinding_Local"
            contract="MyServices.Contracts.IMyService" />
    <endpoint name="TcpService"
            address="net.tcp://localhost/ServiceHost/TheService.svc"
            contract="MyServices.Contracts.IMyService"
            binding="netTcpBinding"
            bindingConfiguration="netTcpWindowsBinding" />
</client>

Any ideas???

Seems like the ConfigurationName in the Generated proxy is just IMyService rather than MyServices.Contracts.IMyService. So in your clients web.config can you just have the contract as IMyService rather than the complete one and test if that works.

This is a bit trivial, but does your app.config relate to the process in which the app is running? For example, if you created your service reference in an assembly / separate project, but call it from an exe that references that assembly, the config needs to be in the app.config in the client exe not the app.config for the assembly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM