我在我的 MT 项目中添加了对 WCF 服务的 Web 引用(此处使用 MonoDevelop 2.4.2)。 我正在尝试回收 Visual Studio 使用的 app.config 文件。我将它复制到我的 MT 的根目录中,并在 MonoDevelop 中指定“复制到输出目录”。仍然不起作用。 在 MonoDevelop 中使用 app.config 的正确方法是什么?
雷内
最佳答案
不幸的是,您不能在 Monotouch 中使用 app.config 文件。您必须自己在代码中创建所有绑定(bind)。在我们的一个项目中,这是我们所做的:
public static ServiceClient GetClient()
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.OpenTimeout = new TimeSpan(0,0,10);
binding.CloseTimeout = new TimeSpan(0,0,10);
binding.SendTimeout = new TimeSpan(0,0,10);
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.BypassProxyOnLocal = false;
binding.AllowCookies = false;
// snip - we set all the properties found in the serverside config file in code here
EndPointAddress endpointAddress = new EndpointAddress("https://www.domain.com/ServiceClient.svc");
ServiceClient client = new ServiceClient(binding, endpointAddress);
return client;
}
您需要遍历并设置在服务器的 app.config 文件中找到的每个属性,确保值完全匹配,否则这将不起作用。 (如果我误解了您的问题,那么我深表歉意!)。
关于mono - 在 MonoDevelop/MonoTouch : how to use the app. 配置文件中使用 WCF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6665941/