Ошибка WCF при размещении службы на Azure
Пытаюсь создать чат на WCF. В локальной сети чат работает идеально, но после публикации на Azure выдаёт ошибку "Тип содержимого text/html; charset=UTF-8 ответного сообщения не соответствует типу содержимого привязки (application/soap+xml; charset=utf-8)" Думаю что это из за CallbackContract, т.к. когда тестировал другой проект без него ошибок не было. Я только начинаю разбираться в WCF и прошу вашей помощи с устранением данной ошибки. Спасибо. Адрес службы: "https://kifir20211004172411.azurewebsites.net/Service1.svc"
IService1.cs
[ServiceContract]
public interface IChatClient
{
[OperationContract(IsOneWay =true)]
void RecievMessage(string user, string message);
}
[ServiceContract(CallbackContract = typeof(IChatClient))]
public interface IService1
{
[OperationContract(IsOneWay = true)]
void Join(string username);
[OperationContract(IsOneWay = true)]
void SendMessage(string message);
}
Service1.svc
[ServiceBehavior(ConcurrencyMode =ConcurrencyMode.Single,InstanceContextMode = InstanceContextMode.Single)]
public class Service1 : IService1
{
Dictionary<IChatClient, string> _users = new Dictionary<IChatClient, string>();
public void Join(string username)
{
var connection = OperationContext.Current.GetCallbackChannel<IChatClient>();
_users[connection] = username;
}
public void SendMessage(string message)
{
var connection = OperationContext.Current.GetCallbackChannel<IChatClient>();
string user;
if (!_users.TryGetValue(connection, out user))
return;
foreach (var other in _users.Keys)
{
if (other == connection)
continue;
other.RecievMessage(user, message);
}
}
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.serviceModel>
<services>
<service name="Chat.Service1">
<endpoint address=""
binding="wsDualHttpBinding"
contract="Chat.IService1">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!--<serviceDebug includeExceptionDetailInFaults="false"/>-->
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsDualHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
App.config сформированный автоматически на клиенте
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IService1" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://kifir20211004172411.azurewebsites.net/Service1.svc"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IService1"
contract="Proxy.IService1" name="WSDualHttpBinding_IService1">
<identity>
<servicePrincipalName value="host/RD0003FF212331" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Возникающая ошибка при запуске клиента
System.ServiceModel.ProtocolException: "Тип содержимого text/html; charset=UTF-8 ответного сообщения не соответствует типу содержимого привязки (application/soap+xml; charset=utf-8). При использовании особого кодировщика необходимо правильно реализовать метод IsContentTypeSupported. Первые 1024 байтов ответного сообщения: "<HTML lang="en"><HEAD><link rel="alternate" type="text/xml" href="https://kifir20211004172411.azurewebsites.net/Service1.svc?disco"/><STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{display: block; font-size: 1em;}</STYLE><TITLE>Service1 Service</TITLE></H"."
Код на клиенте
static void Main(string[] args)
{
InstanceContext context = new InstanceContext(new MyCallback());
Proxy.Service1Client server = new Proxy.Service1Client(context);
Console.WriteLine("enter username");
var username = Console.ReadLine();
server.Join(username);//тут возникает вышеописанная ошибка
Console.WriteLine();
Console.WriteLine("Enter message");
Console.WriteLine("Press Q to Exit");
var message = Console.ReadLine();
while(message!="Q")
{
if (!string.IsNullOrEmpty(message))
server.SendMessage(message);
message = Console.ReadLine();
}
}