动态绑定给出错误

时间:2015-07-06 12:12:03

标签: c# wcf

我不想使用web.config来引用绑定。所以我创建了动态绑定

WSHttpBinding httpBinding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential, true);
            httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            httpBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
            httpBinding.Security.Message.EstablishSecurityContext = false;
            EndpointAddress address = new EndpointAddress("https:myservice/service.svc);
            myService = new ServiceClient(httpBinding, address);
            if (myService .ClientCredentials != null)
            {
                myService .ClientCredentials.UserName.UserName = "xxx";
                myService .ClientCredentials.UserName.Password = "dfdf";
            }

但是当我调用它然后我得到错误

  

无法在没有安全对话的情况下建立可靠的会话。启用安全对话。

这种方法有什么问题?

0 个答案:

没有答案