vb.net - 连接到 Web 服务 - token 提供者无法获取目标的 token

标签 vb.net soap app-config

我正在尝试连接到 SOAP Web 服务,但收到此错误:

The token provider cannot get tokens for target 'http://realurl.com/myservice.svc'

提供该服务的公司向我发送了这个 app.config 示例代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <!-- Specify UserName and Password of context user -->
        <add key="UserName" value="xxxxxx" />
        <add key="Password" value="xxx" />
    </appSettings>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="ValuationServiceEndpoint" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false" >
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="TransportWithMessageCredential" >
                        <message clientCredentialType="UserName"  establishSecurityContext="false"/>
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://sampleurl.com/service.svc"
                binding="wsHttpBinding"  bindingConfiguration="ValuationServiceEndpoint"
                contract="Provider.ValuationService.ValuationService" name="ValuationServiceEndpoint" >
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

不过,我在使用这段代码时遇到了问题,因为他们给我的端点地址是 HTTP 而不是 HTTPS。这意味着安全模式 TransportWithMessageCredential 在这里不起作用,因此我将其更改为 Message

这是我当前的代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <appSettings>
        <add key="Username" value="myuser" />
        <add key="Password" value="mypass" />
    </appSettings>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="ValuationServiceEndpoint">
                    <security mode="Message">
                        <message clientCredentialType="UserName" establishSecurityContext="false" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://realurl.com/service.svc"
                binding="wsHttpBinding" bindingConfiguration="ValuationServiceEndpoint"
                contract="Provider.ValuationService.ValuationService" name="ValuationServiceEndpoint" />
        </client>
    </system.serviceModel>
</configuration>

我不明白为什么会收到 token 错误。有人可以帮忙吗?

谢谢!

最佳答案

很抱歉两个月后才回复你的帖子,但至少你会知道为什么它不起作用。

你的问题其实很简单。服务器和客户端之间的安全模式不匹配。服务器正在等待 TransportWithMessageCredential,而客户端正在提供 Message

如果您只想使用密码安全,请在两侧使用Message。如果您想使用 HTTPS,则需要在两侧提供 TransportWithMessageCredential

关于vb.net - 连接到 Web 服务 - token 提供者无法获取目标的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36942758/

相关文章:

c# - log4net:错误无法找到配置部分 'log4net'

java - 是否可以生成填充了安全 header 的 WSDL?

java - 如何使用 Rest-assured 验证具有多个命名空间的 SOAP XML 响应中的特定节点?

c# - 良好的 3270 模拟器 (.NET)

vb.net - 在多个字段、SUM 和 COUNT 上使用 GROUP BY 进行 Linq 查询

php - 使用 PHP 进行 SOAP 身份验证

c# - ConfigurationManager 返回 null 而不是字符串值

C# 程序集绑定(bind)重定向 - Newtonsoft.Json

.net - 我可以导入命名空间,但无法使用完全限定的类名

sql - REPLACE INTO 查询是好的做法吗?