我正在尝试连接到用Java编写的Web服务,但有些东西我无法弄清楚.
使用WCF和customBinding,几乎所有内容似乎都很好,除了SOAP消息的一部分,因为它缺少Nonce和Created部分节点.显然我错过了一些东西,所以如果你能指出我正确的方向,那就非常感激了.
这是自定义绑定:
<binding name="CustomHTTPBinding">
<security includeTimestamp="false" authenticationMode="UserNameOverTransport" defaultAlgorithmSuite="Basic256" requireDerivedKeys="True"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
</security>
<textMessageEncoding maxReadPoolSize="211" maxWritePoolSize="2132" messageVersion="Soap11"
writeEncoding="utf-8"/>
<httpsTransport />
</binding>
Run Code Online (Sandbox Code Playgroud)
这是消息的相关部分:
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-c306efd1-e84c-410e-a2ad-1046b368582e-1">
<o:Username>
<!-- Removed-->
</o:Username>
<o:Password>
<!-- Removed-->
</o:Password>
</o:UsernameToken>
</o:Security>
Run Code Online (Sandbox Code Playgroud)
这就是它的外观:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-25763165">
<wsse:Username>..</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">..</wsse:Password>
<wsse:Nonce>6ApOnLn5Aq9KSH46pzzcZA==</wsse:Nonce>
<wsu:Created>2009-05-13T18:59:23.309Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
Run Code Online (Sandbox Code Playgroud)
所以问题是:我如何在安全部分中引入Nonce和Created元素?
为此,我一直都在网上.我刚刚做了一段时间的恶魔,我试图消费的网络服务供应商拒绝正式支持WCF作为一种消费方法.
我不是网络服务专家,所以我会尽力记录和解释这篇文章,但无论如何,如果你需要的话,请求更多的信息,希望我能够提供任何必要的东西.
服务
在我的公司,我们使用公开服务的供应商应用程序.该应用程序是用java编写的,看起来wsdl是用Apache Axis 1.2创建的.
代码
我的遗留代码使用WSE 3.0.特别是,它使用最后自动添加"WSE"的代理类.这允许我使用更简单的身份验证方案(我可以让它工作的唯一方法).我不需要使用证书.我使用的衍生物SecurityPolicyAssertion,并将其包装在一个Policy传递给SetPolicy客户端类的方法的对象中.以下是创建客户端工作实例所需的全部内容:
MyWebServiceWse api = new MyWebServiceWse();
api.Url = myUrl;
api.SetPolicy(new Policy(new MyDerivedSecurityAssertion(user, pass)));
Run Code Online (Sandbox Code Playgroud)
我的默认,开箱即用的WCF代码(使用服务引用生成)不接受凭据,所以我知道这是一个问题.我已经在网上阅读了关于security在我的网站中使用不同或绑定设置的各种内容app.config,但没有任何内容完全奏效.经过大量修补后,我最常见的错误是WSDoAllReceiver: Request does not contain required Security header.
这是app.config.也许我们可以先告诉我这里应该改变什么来促进传递证书 - 再次,我在网上看到了不同的意见.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MySoapBinding" 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" …Run Code Online (Sandbox Code Playgroud) 我是WSE和WCF的新手,我正在尝试使用WCF使用Web服务,但所有示例文档都适用于VS2005 + WSE.此Web服务使用WS-Security 1.0.我已经通过visual studio添加了一个服务引用,但我不知道如何在WCF中执行以下代码的等效操作:
// 1. Initialize the web service proxy
PartnerAPIWse integrationFramework = new PartnerAPIWse();
// 2. Set the username/password. This is using the Username token of WS-Security 1.0
UsernameTokenProvider utp = new UsernameTokenProvider("username", "password");
integrationFramework.SetClientCredential<UsernameToken>(utp.GetToken());
// 3. Declare the policy
Policy policy = new Policy(new UsernameOverTransportAssertion());
integrationFramework.SetPolicy(policy);
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序通过https连接到实现WS-Security的基于SOAP的Web服务.Web服务是用Java编写的,需要纯文本密码以及正确设置的时间戳.
经过大量的谷歌搜索和实验,我无法弄清楚如何配置我的WCF客户端与此服务进行交互.除了正确答案之外,我还要感谢指向WCF和SOAP的教程的链接.
我当前客户端的app.config如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyServiceSoapBinding" 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="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
<!--security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security-->
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://p1.my.com/tx/services/MyService"
binding="basicHttpBinding" bindingConfiguration="MyServiceSoapBinding"
contract="My.IMyService" name="MyServiceEndpointPort" />
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
并且客户端代码如下所示:
string response;
try
{
MyService.MyServiceClient svc = …Run Code Online (Sandbox Code Playgroud) 我们真的被困在这里,所以我决定请你帮忙.
昨天我被要求帮助使用Web服务,获取WSDL的URL以及要使用的用户凭据.我从来没有真正与Web服务有任何关系,但对它们有一个大概的想法并看到一些例子,我认为它不会那么糟糕.显然我错了,因为我现在被困住了.
一切似乎都很好,代理类(或客户端)已生成,构建请求和发送它们也很好,除了身份验证部分.我们似乎无法弄明白该怎么做.
使用:
client.ChannelFactory.Credentials.UserName.UserName = "myusername";
client.ChannelFactory.Credentials.UserName.Password = "mypassword";
Run Code Online (Sandbox Code Playgroud)
似乎不起作用.(当我检查由client.Endpoint.Binding.CreateBindingElements()返回的BindingElementCollection时,没有SecurityBindingElement)
我已经尝试了很多其他方法,但我认为我缺少一些基本的东西,缺乏文档也没有真正帮助.
所以问题是:如何使用WCF调用Web服务时发送用户名和密码?
编辑: 只是为了澄清,请求应包含类似于此的内容:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-25763165">
<wsse:Username>username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">1DiaGTkOLk/CZhDaEpbkAaKRfGw=</wsse:Password>
<wsse:Nonce>6ApOnLn5Aq9KSH46pzzcZA==</wsse:Nonce>
<wsu:Created>2009-05-13T18:59:23.309Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
Run Code Online (Sandbox Code Playgroud)