私は WCF を試していて、サーバーに DataContract を追加し、ServiceContract を更新しました。ServiceReference が最初にクライアントに追加されたとき、両方を同じ PC で実行していたので、localhost を使用しました。私は今、イーサネットケーブルを介して2台のPCを接続し、その方法でサービス参照を更新しようとしました。LAN上のサーバーのIPアドレスをに設定しました192.168.10.10
。次のコードは、サーバー フォームでボタンがクリックされたときに実行されます。
private void btnCommenceService_Click(object sender, EventArgs e)
{
host = new ServiceHost((typeof(Service)), new Uri[] { new Uri("http://localhost:9000")});
host.AddServiceEndpoint(typeof(IServices),
new WSDualHttpBinding(),
"ServerService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
txtStatus.Text = "Service is open.";
}
両方の PC でファイアウォールをオフにし"http://192.168.10.10"
、クライアント PC からアドレスを正常に ping しました。ブラウザに入力すると、ランダムなWebページにもアクセスできました。
クライアントで、ソリューションをクリックして「サービス参照の追加」を選択し、入力すると
"http://192.168.10.10"
"http://192.168.10.10:9000"
"http://192.168.10.10:9000/ServerService"
それらはすべて何らかの形式のエラーで返されます。通常は次の行に沿ったものです。
The document at the url http://192.168.10.10:9000/ was not recognised as a known document type.
The error message for each known type may help u fix the problem:
-Report from 'XML Schema' is The document format is not recognised(the content type is 'text/html;charset=utf-8').'.
Report from DISCO Document is There was an error downloading `'http://localhost:9000/?disco'.'.`
Unable to connect to the remote server.
No connection could be made because the target machine actively refused it 127.0.0.1:9000
etc
アドレスにアクセスしてpingを実行できるのに、LAN経由で機能しない理由について誰かが指摘していますか?