使用WCF的HTTPS webservice

时间:2014-03-25 13:23:58

标签: wcf

我尝试在我的最后通过代理连接到https网络服务。

下面的

是代码段

    Dim strProxyURL As String = "http://myproxy.com"
    Dim mypingRequest As New pingRequest()
    Dim httpUri As New Uri("https://mysite.com")
    Dim mybinding As New WSHttpBinding()
    Dim remoteAddress As New EndpointAddress(httpUri)

    mybinding.UseDefaultWebProxy = True

    mybinding.BypassProxyOnLocal = True


    mybinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Windows

    mybinding.MessageEncoding = WSMessageEncoding.Mtom
    mybinding.TextEncoding = System.Text.Encoding.UTF8
    mybinding.Security.Mode = SecurityMode.TransportWithMessageCredential 'TransportWithMessageCredential

    mybinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows

    Dim myMBClient As New v1_PortTypeClient(mybinding, remoteAddress)

    myMBClient.ClientCredentials.Windows.ClientCredential.UserName = "username"
    myMBClient.ClientCredentials.Windows.ClientCredential.Password = "pwd"

    myMBClient.ping()

当我使用代理时我需要错误代理身份验证错误 如果我从桌面删除代理并使用直接互联网然后我去网站Web服务,但即使认为给出正确的用户名和密码也无法登录

1 个答案:

答案 0 :(得分:0)

问题已解决。 WCF Web服务使用自定义绑定因此错误。我还添加了webrequest.defaultwebproxy和凭据,以便在请求客户端时通过Web代理进行访问WCF Custom Http Proxy Authentication