我已成功使用 CUB 调用 Web 服务,但我依赖于 app.config 中的配置。我想知道是否可以在不向 app.config 添加任何条目的情况下通过代码生成绑定。
我尝试了以下方法:
ClearUsernameBinding binding = new ClearUsernameBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8087/SampleService/");
EchoServiceReference.EchoServiceClient client = new EchoServiceReference.EchoServiceClient(binding, address);
client.ClientCredentials.UserName.UserName = "yaron";
client.ClientCredentials.UserName.Password = "1234";
Console.WriteLine(client.EchoString("hi"));
但我得到了错误:
Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)' does not support adding Message Headers.