我正在尝试连接到 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/