Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过HTTPS使用WCF中的WS-Security服务?_Wcf_Soap_Ws Security - Fatal编程技术网

如何通过HTTPS使用WCF中的WS-Security服务?

如何通过HTTPS使用WCF中的WS-Security服务?,wcf,soap,ws-security,Wcf,Soap,Ws Security,我正在尝试使用支持WS-Security的WCF服务。身份验证使用UsernameToken工作。我对WCF web服务客户端不是很熟悉,但我认为下面的配置适用于常规HTTP通信。我(主要)用来配置它。主要区别在于我使用了VS2010“添加服务引用”UI而不是命令提示符 我的问题是,我需要通过HTTPS来实现这一点。当我在app.config中使用时,我相信我的soap信封包含所需的WS-Security头。我不能确定,因为我不能让日志工作。但是,我得到以下错误:提供的URI方案“https”无

我正在尝试使用支持WS-Security的WCF服务。身份验证使用UsernameToken工作。我对WCF web服务客户端不是很熟悉,但我认为下面的配置适用于常规HTTP通信。我(主要)用来配置它。主要区别在于我使用了VS2010“添加服务引用”UI而不是命令提示符

我的问题是,我需要通过HTTPS来实现这一点。当我在app.config中使用
时,我相信我的soap信封包含所需的WS-Security头。我不能确定,因为我不能让日志工作。但是,我得到以下错误:
提供的URI方案“https”无效;应为“http”。参数名称:通过

下面是我的app.config文件的内容,以及我的客户端代码示例

<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Omitted" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Message">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" negotiateServiceCredential="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://omitted.com/service" binding="wsHttpBinding" bindingConfiguration="Omitted" contract="Omitted.Omitted" name="Omitted" />
</client>
  </system.serviceModel>

感谢500-内部服务器错误帮助我解决了这个问题。以下是我采取的步骤:

  • 使用Visual Studio/WCF生成代理
  • 将安全模式更改为TransportWithmessageCredential
  • 使用以下代码指定用户名/密码
  • var client=new WebServiceClient(); client.ClientCredentials.UserName.UserName=“UserName”; client.ClientCredentials.UserName.Password=“Password”;
  • 如果您得到一个响应,但WCF在处理它时抱怨,那么响应中可能缺少一个时间戳。如果是这样的话,试试这个来解决它
  • //WCF抱怨缺少时间戳(http://www.west-wind.com/weblog/posts/2007/Dec/09/Tracing-WCF-Messages) var elements=service.Endpoint.Binding.CreateBindingElements(); elements.Find().IncludeTimestamp=false; service.Endpoint.Binding=新的CustomBinding(元素);
    HTTPS是一种传输安全模式。是的,但如何使用消息安全性?使用UsernameToken是否需要消息安全性?请使用TransportWithMessageCredential模式。请原谅,我的帖子似乎有问题。
    var service = new OmittedClient();
    service.ClientCredentials.UserName.UserName = "username";
    service.ClientCredentials.UserName.Password = "password";    
    var response = service.DoSomething(new DoSomethingRequest());
    
    var client = new WebServiceClient(); client.ClientCredentials.UserName.UserName = "USERNAME"; client.ClientCredentials.UserName.Password = "PASSWORD"; // WCF complains about a missing timestamp (http://www.west-wind.com/weblog/posts/2007/Dec/09/Tracing-WCF-Messages) var elements = service.Endpoint.Binding.CreateBindingElements(); elements.Find().IncludeTimestamp = false; service.Endpoint.Binding = new CustomBinding(elements);