私はこのインターフェースを持っています:
[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>
ServiceHost を使用して WPF アプリケーションで自己ホストされます。このコードは次のようになります。
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 Request が返されます。Visual Studio の [サービス参照の追加] を使用して WCF クライアントを作成しようとすると、次のエラーが発生します。
「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()); }
}
誰かが私が見逃したものについていくつかの洞察を与えることができますか. これは簡単な演習になるはずでした:!
ティア。