У меня такой интерфейс:
[ServiceContract]
public interface ILocationService
{
[OperationContract]
bool RegisterForNotification(string name, string uri);
[OperationContract]
bool UnRegisterForNotification(string name);
}
и эта услуга:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class LocationBasedService : ILocationService
{
#region Registrations
public bool RegisterForNotification(string name, string uri)
{
return true;
}
public bool UnRegisterForNotification(string name)
{
return true;
}
#endregion
}
и следующая конфигурация:
<configuration>
<system.serviceModel>
<services>
<service name="PushNotifications.Server.Service.LocationBasedService" >
<endpoint address="http://localhost:8000/LocationBasedService"
binding="basicHttpBinding"
contract="Services.Interface.ILocationService"/>
</service>
</services>
</system.serviceModel>
Самостоятельное размещение в приложении WPF с использованием ServiceHost. Код для этого выглядит так:
private void startSrv_Click(object sender, RoutedEventArgs e)
{
try
{
host = new ServiceHost(typeof(LocationBasedService));
host.Open();
AddDiagnosticMessage("service successfully initialized");
AddDiagnosticMessage(string.Format("{0} is up and running with these end points", host.Description.ServiceType));
foreach (var se in host.Description.Endpoints)
AddDiagnosticMessage(se.Address.ToString());
}
catch (TimeoutException ex)
{
AddDiagnosticMessage(string.Format("The service operation timeod out. {0}", ex));
}
catch (CommunicationException ex)
{
AddDiagnosticMessage(string.Format("Could not start host service. {0}", ex));
}
catch (Exception ex)
{
AddDiagnosticMessage(ex.Message);
}
}
Сервис запускается без исключений. Однако, когда я отправляю URL-адрес http://localhost:8000/LocationBasedService в свой браузер, я получаю HTTP 400 Bad Запрос. Если я попытаюсь создать клиент WCF с помощью Visual Studio Add Service Reference, я получаю следующую ошибку:
http: // localhost: 8000 / LocationBasedService. Тип контента application / soap + xml; charset = utf-8 не поддерживался службой http://localhost:8000/LocationBasedService. Привязки клиента и службы могут не совпадать. Удаленный сервер возвратил ошибку: (415) Невозможно обработать сообщение, поскольку тип содержимого «application / soap + xml; charset = utf-8 'не был ожидаемым типом' text / xml; charset = utf-8 '.. Если служба определена в текущем решении, попробуйте создать решение и снова добавить ссылку на службу.
ЕСЛИ я пытаюсь вызвать клиента, используя следующий код, я получаю исключение тайм-аута.
private void Button_Click(object sender, RoutedEventArgs e)
{
statusMessages.Add(GetFormattedMessage("initiailing client proxy"));
var ep = new EndpointAddress("http://localhost:8000/LocationBasedService");
var proxy = ChannelFactory<ILocationService>.CreateChannel(new BasicHttpBinding(), ep);
var register = proxy.RegisterForNotification("name1", @"http://google.com");
if (register)
{ Console.Writeline(register.ToString()); }
}
Не мог бы кто-нибудь дать некоторое представление о том, что я пропустил. Это должно было быть легкое упражнение:!
TIA.