如何在运行时设置端点
|
我有基于本教程的应用程序
我用来测试与服务器(在客户端应用程序中)的连接的方法:
public class PBMBService : IService
{
private void btnPing_Click(object sender, EventArgs e)
{
ServiceClient service = new ServiceClient();
tbInfo.Text = service.Ping().Replace(\"\\n\", \"\\r\\n\");
service.Close();
}
//other methods
}
服务主要功能:
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri(\"http://localhost:8000/PBMB\");
ServiceHost selfHost = new ServiceHost(typeof(PBMBService), baseAddress);
try
{
selfHost.AddServiceEndpoint(
typeof(IService),
new WSHttpBinding(),
\"PBMBService\");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
Console.WriteLine(\"Serwis gotowy.\");
Console.WriteLine(\"Naciśnij <ENTER> aby zamknąć serwis.\");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine(\"Nastąpił wyjątek: {0}\", ce.Message);
selfHost.Abort();
}
}
}
在app.config
中,我有:
<client>
<endpoint address=\"http://localhost:8000/PBMB/PBMBService\" binding=\"wsHttpBinding\"
bindingConfiguration=\"WSHttpBinding_IService\" contract=\"IService\"
name=\"WSHttpBinding_IService\">
<identity>
<userPrincipalName value=\"PPC\\Pawel\" />
</identity>
</endpoint>
</client>
我可以从这里更改IP。但是如何在运行时更改它(即从文件中读取地址/ IP)?
没有找到相关结果
已邀请:
2 个回复
填盖
拟僚疽刊剔
您可以将其与以下代码一起使用: