我使用Visual Studio 2008创建了一个Web服务代理,它为我创建了app.config中的以下条目:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyNameHandlerSoapBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.***/***/***"
binding="basicHttpBinding" bindingConfiguration="MyNameHandlerSoapBinding"
contract="***.MyNameHandler" name="MyName">
</endpoint>
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
webservice有用户名/密码验证,所以我需要在这里添加它.
我在WCF文档的海洋中有点迷失,我想我必须从basicHttpBinding更改为wsHttpBinding或customBinding才能添加身份验证元素,但我真的不明白它.任何人都可以提供任何快速提示或任何有用的链接,说明如何做到这一点?
编辑:
我将安全部分更改为:
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None"
realm="" />
</security>
Run Code Online (Sandbox Code Playgroud)
并在代码中添加:
ws.ClientCredentials.UserName.UserName = "";
ws.ClientCredentials.UserName.Password = "";
Run Code Online (Sandbox Code Playgroud)
现在它似乎可能正在使用凭据,但它给了我错误:
提供的URI方案'http'是无效的URI预期'https'
我甚至都不知道这是不是正确的方法......
我有一个WCF客户端连接到基于Java的Axis2 Web服务(在我的控制之外).它即将应用WS-Security,我需要修复.NET客户端.但是,我正在努力提供正确的身份验证.我知道WSE 3.0可能会让它变得更容易,但我宁愿不再使用过时的技术.
SOAP消息应如下所示:
<wsse:UsernameToken>
<wsse:Username><!-- Removed--></wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"><!-- Removed--></wsse:Password>
<wsse:Nonce><!-- Removed--></wsse:Nonce>
<wssu:Created>2010-05-28T12:50:33.675+01:00</wssu:Created>
</wsse:UsernameToken>
Run Code Online (Sandbox Code Playgroud)
但是,我的看起来像这样:
<s:Header>
<h:Security xmlns:h="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></h:Security>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2010-06-23T10:31:23.441Z</u:Created>
<u:Expires>2010-06-23T10:36:23.441Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="uuid-d329b3b2-6a1f-4882-aea6-ec6b8a492de7-1">
<o:Username>
<!-- Removed-->
</o:Username>
<o:Password>
<!-- Removed-->
</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
Run Code Online (Sandbox Code Playgroud)
我的客户端看起来像这样:PS注意所需的 SecurityHeaderType参数.那是什么?
public MyAck SendRequest(MyRequest request)
{
RemoteServicePortTypeClient client = new RemoteServicePortTypeClient();
client.ClientCredentials.UserName.UserName = "JAY";
client.ClientCredentials.UserName.Password = "AND";
// what is the difference between the two different Credential …Run Code Online (Sandbox Code Playgroud) 请不要使用WCF跟踪工具回答,除非提供有关如何捕获实际消息(包括标头和错误)的明确说明.此链接不起作用.
此外,IClientMessageInspector除非您知道如何使其包含所有标题(它不包含)并捕获具有不解析的错误元素的响应,否则不要回答.
使用pre-wcf Web服务,您可以编写一个SoapExtension完美无缺的工作.
我想保护一个简单的WCF服务,从客户端发送用户名和密码,并使用CustomUserNamePasswordValidator.对于我在Web上尝试的每个例子,我都被困在巨大的配置和模糊的错误,SSL,证书等...
最相似的替代方法(让你更好地理解)是将"serviceUsername"和"servicePassword"参数(可能是散列)传递给服务的每个方法并在此处执行身份验证,但我承认这是一个丑陋和肮脏的解决方案.
我不介意加密凭证,因为它不是一个安全关键服务.我只需要一种基本的保护形式.
谢谢!
亚历山德罗
wcf ×4
.net ×2
axis2 ×1
c# ×1
https ×1
logging ×1
security ×1
wcf-security ×1
web-services ×1
ws-security ×1