私はWCF The Right Way ... The Manual Way to setup my WCF Service の方法に大まかに従っています。
次のような手動で生成されたプロキシ クラスがあります。
// Setup a client so we can call our web services.
public class EmployeeClient :IEmployeeService
{
private readonly IEmployeeService EmployeeChannel;
public EmployeeClient(Binding binding, string address)
{
var endpointAddress = new EndpointAddress(address);
EmployeeChannel = new ChannelFactory<IEmployeeService>
(binding, endpointAddress).CreateChannel();
}
public EmployeeResponse SaveOrUpdateEmployee(EmployeeContract employee)
{
return EmployeeChannel.SaveOrUpdateEmployee(employee);
}
}
次に、これらのサービスのいくつかを呼び出したいと思います。しかし、構成ファイルを使用したくありません (いくつかの統合テストをセットアップしており、必要以上の依存関係は必要ありません)。
私は現在、次のようにそれらを呼び出そうとしています:
serviceHost = SelfServiceHost.StartupService();
employeeClient = new EmployeeClient(new BasicHttpBinding(),
SelfServiceHost.StartUpUrl);
EmployeeResponse employeeResponse = employeeClient.SaveOrUpdateEmployee(emp);
これを行うと、次の例外が発生します。
System.ServiceModel.ProtocolException: コンテンツ タイプ text/xml; charset=utf-8 はサービスhttp://localhost:8090/EmployeeServiceでサポートされていませんでした。クライアントとサービスのバインディングが一致していない可能性があります。---> System.Net.WebException: リモート サーバーがエラーを返しました: (415) コンテンツ タイプが 'text/xml; であるため、メッセージを処理できません。charset=utf-8' は、予期されたタイプ 'application/soap+xml;' ではありませんでした。charset=utf-8'..
コードのみで動作するサービスへの呼び出しを取得するには、何をする必要がありますか?