【问题标题】:Setting up an authorized connection between a php webservice and a C# WCF client在 php webservice 和 C# WCF 客户端之间建立授权连接
【发布时间】:2011-07-05 12:44:53
【问题描述】:

我们的 php 网络服务为客户提供网络功能。我们使用以下代码进行身份验证。

$client = new SoapClient("some.wsdl", 
                         array('login' => "some_name",
                               'password' => "some_password"
                         ));

客户端是用 C# 构建的,我们可以在没有身份验证的情况下建立连接,但我们无法应用身份验证。

我们应该为客户提供什么样的属性? 我已经尝试将此配置与用户名凭据结合使用。

        <basicHttpBinding>
            <binding name="webserviceControllerBinding">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Basic"/>
                </security>
            </binding>
        </basicHttpBinding>

client.ClientCredentials .UserName.UserName = "用户名"; client.ClientCredentials.UserName.Password = "密码";

我们的 php 服务使用什么样的安全性? 我们如何在不使用证书或 https 的情况下建立可靠的身份验证连接。

【问题讨论】:

    标签: c# php wcf soap


    【解决方案1】:

    【讨论】:

    • 我不得不使用 wcfextras.codeplex.com 来验证 php 客户端到 wcf 服务(据我所知,你的情况是其他方式)
    【解决方案2】:
             MessageHeader header= MessageHeader.CreateHeader("My-CustomHeader","http://myurl","Custom Header.");
    
               using (phptoebiTestclient.ServiceReference1.webserviceControllerPortTypeClient client = new phptoebiTestclient.ServiceReference1.webserviceControllerPortTypeClient())
               {
                   using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
                   {
                       OperationContext.Current.OutgoingMessageHeaders.Add(header);
                       HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
                       byte[] toEncodeAsBytes    = System.Text.ASCIIEncoding.ASCII.GetBytes("username:password");                       
                       httpRequestProperty.Headers.Add("Authorization: Basic "+ System.Convert.ToBase64String(toEncodeAsBytes));                                              
                       OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
                       string str = client.getVacanciesReference("");
                   }                                 
               }
    

    上面的代码已经解决了我的问题(我用这些网址作为参考)

    http://caught-in-a-web.blogspot.com/2008/04/how-to-add-custom-http-header-in-wcf.html
    http://en.wikipedia.org/wiki/Basic_access_authentication

    【讨论】:

      【解决方案3】:

      试试

      <security mode="TransportWithMessageCredential">
         <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
      

      更新:应该是 TransportWithMessageCredential 模式

      【讨论】:

      • 我收到以下错误消息“BasicHttp 绑定要求 BasicHttpBinding.Security.Message.ClientCredentialType 等效于用于安全消息的 BasicHttpMessageCredentialType.Certificate 凭据类型。为 UserName 凭据选择 Transport 或 TransportWithMessageCredential 安全性。而且我不想使用证书
      猜你喜欢
      • 2011-05-20
      • 2012-04-24
      • 2017-03-16
      • 2015-07-28
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多