Добрый день. У меня возникла ошибка при построении клиента запросов к WCF службе, то есть при попытки связаться
пишет что не нашел endpoint:
System.InvalidOperationException: Could not find endpoint element with name 'http://localhost:8741/WCFServiceMet' and contract 'TestClientService.Program+IWCFService' 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.
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
at TestClientService.Program.Main(String[] args) in f:\Microsoft Visual Studio 2012\TestClientService\TestClientService\Program.cs:line 28
сама WCF служба работает и при ее добавлении в VS обнаруживает себя, отвечает на запрос wsdl, ошибок при запуске не выдает (хотя почему то я не вижу что бы она слушала указанный порт), ладно к делу вот код клиента
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.IO;
namespace TestClientService
{
class Program
{
[ServiceContract]
public interface IWCFService
{
[OperationContract]
string SayHello(string _name);
[OperationContract]
int Addition(int a, int b);
string TestString(string _mas);
[OperationContract]
string TestHello(string _variable);
}
static void Main(string[] args)
{
try
{
ChannelFactory<IWCFService> myChannelFactory = new ChannelFactory<IWCFService>("http://localhost:8741/WCFServiceMet");
IWCFService WCFClientOpen = myChannelFactory.CreateChannel();
string result = WCFClientOpen.TestHello("Hello World");
Console.WriteLine("SayHello:{0}", result);
myChannelFactory.Close();
Console.ReadKey();
}
catch (Exception ErrorException)
{
TextWriter tw = File.AppendText(@"c:\logs\ClientLog.txt");
tw.WriteLine(ErrorException);
tw.Close();
}
}
}
}
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="standart" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8741/WCFServiceMet"
binding="basicHttpBinding" bindingConfiguration="standart"
contract="TestService.IWCFService" name="standart" />
</client>
</system.serviceModel>
</configuration>
адрес точки в службе
<service behaviorConfiguration="Test_Behavior" name="TestService.WCFService">
<endpoint address="http://localhost:8741/WCFServiceMet" binding="basicHttpBinding" bindingConfiguration="NewBindingTest"
name="standart" contract="TestService.IWCFService" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint binding="mexHttpBinding" name="mex"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8741/" />
</baseAddresses>
что я упустил при создании.