2

私は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'..

コードのみで動作するサービスへの呼び出しを取得するには、何をする必要がありますか?

4

1 に答える 1

6

あなたが説明したことから、バインディングは互換性のある方法で構成されていません。

私はWCFホストが持っていてwsHttpBinding、あなたのクライアント側が持っていると思いますBasicHttpBinding...

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f29cd9c8-3c89-43d2-92ae-d2a270ab86b9/を参照してください。

于 2011-08-17T16:51:19.117 に答える