连接到Web服务 - 令牌提供程序无法获取目标

时间:2016-04-29 15:55:31

标签: vb.net soap app-config

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

  

令牌提供商无法获取目标“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>

我无法弄清楚为什么我会收到令牌错误。有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

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

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

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