Reputation: 9416
[ServiceContract]
public interface IService1
{
[OperationContract]
DataTable GetADUserList(string strUserName, string strFirstName, string strLastName, string strEmail, string domain);
}
I have a WCF service hosted in IIS with the sample service contract above. The service web.config file settings are as below.
Full WCF Web.config file
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="notSecureBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<binding name="SecureBinding">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://ServerName.myDomain.org/ADSearcher/Service1.svc"
binding="customBinding"
bindingConfiguration="notSecureBinding"
contract="ADSearcher.IService1"
name="notSecureBinding" />
<endpoint address="http://ServerName.myDomain.org/ADSearcher/Service1.svc"
binding="customBinding"
bindingConfiguration="SecureBinding"
contract="ADSearcher.IService1"
name="SecureBinding" />
</client>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
And i'm trying to access the service programmatically as below.
EndpointAddress endpointAddress = new EndpointAddress("http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser = new ChannelFactory<IService1>("notSecureBinding", endpointAddress).CreateChannel();
The above code is throwing the error below
Could not find endpoint element with name 'notSecureBinding' and contract 'ADSearcher.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
I can't seem to figure out what i'm doing wrong here or is there a better alternative to access this service programmatically?
Upvotes: 3
Views: 5314
Reputation: 31760
Could not find endpoint element with name 'customBinding'....in the ServiceModel client configuration section
This is because you are defining two client endpoints in your config file. And they are named:
So the error message is correct, there is no endpoint element with name "customBinding".
I think you need to do this:
IService1 ADUser = new ChannelFactory<IService1>("<either of the two bindings you defined>").CreateChannel();
Do i need to configure any thing related to WCF in the ASP.NET MVC application's web.config file?
OK so now I understand. You are hosting the WCF service in your ASP.NET website. And you're trying to call it from somewhere else I assume?
You definitely need to define a <system.serviceModel />
section in your web.config, which will tell IIS how to host your service.
At the moment, the configuration you gave posted above defines to client endpoints. These do not reference service endpoints, but rather is client config designed to allow you to call services. The hint is in the name of the section node: <client />
. To define service endpoints that you wish to expose you need to put your endpoint config in a <service />
section. In your case it may only be necessary to change the "client" to "service" to make it all work.
The code which is calling the service may or may not need client configuration in the app.config file. You say you are calling it programatically (although without seeing your full client code I don't know that you are doing enough to satisfy the WCF client call stack), in which case you don't need client config. I hope this makes things clearer for you.
Upvotes: 0
Reputation: 45252
In your endpoint, you are specifying a contract of type Data.GetData
. The contract is of type IService1
, and by default, the contract name should be the typename of the service interface.
If you really want your IService
to be referred to as Data.GetData
, you can specify the identifying name via the ServiceContractAttribute
:
[ServiceContract(ConfigurationName = "Data.GetData")]
public interface IService1
{
[OperationContract]
DataTable GetADUserList(string strUserName, string strFirstName, string strLastName, string strEmail, string domain);
}
Upvotes: 1