如何解决SOAP 标头定义中的 SOAP 安全 UsernameToken
我正在尝试连接到客户端的传送 Web 服务,但需要帮助在 SOAP 标头定义中添加 oasis WS-Security Usernametoken。
是否可以在不使用客户端代码的情况下将其添加到客户端应用程序的 app.config 中?
我已经为我的 VB.Net 项目添加了一个新的服务引用,这在 app.config 部分添加了很多额外的条目,即参见我的 app.config 的附加 system.serviceModel 部分。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IBookingMetadata">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_IBooking">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_IBulletins">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_ITiMetable">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_IMetadata">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_IUserInfo">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_ICheckin">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_ICustomsInfo">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBookingMetadata"
contract="FreightlinkWebServices.IBookingMetadata" name="BasicHttpBinding_IBookingMetadata">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBooking"
contract="FreightlinkWebServices.IBooking" name="BasicHttpBinding_IBooking">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBulletins"
contract="FreightlinkWebServices.IBulletins" name="BasicHttpBinding_IBulletins">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITiMetable"
contract="FreightlinkWebServices.ITiMetable" name="BasicHttpBinding_ITiMetable">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMetadata"
contract="FreightlinkWebServices.IMetadata" name="BasicHttpBinding_IMetadata">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserInfo"
contract="FreightlinkWebServices.IUserInfo" name="BasicHttpBinding_IUserInfo">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckin"
contract="FreightlinkWebServices.ICheckin" name="BasicHttpBinding_ICheckin">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
<endpoint address="https://freightservicestest.stenaline.com/Host.Web.FWS/Service.svc/ReservationService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomsInfo"
contract="FreightlinkWebServices.ICustomsInfo" name="BasicHttpBinding_ICustomsInfo">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Usernametoken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:Usernametoken>
</wsse:Security>
</headers>
</endpoint>
</client>
</system.serviceModel>
正如您从上面看到的,我尝试自己添加 oasis WS-Security 标头部分,并且所有编译都很好。但是,当我尝试运行应用程序并调用 Web 方法时,出现以下错误。
未提供用户名。在 ClientCredentials 中指定用户名。
我真的不知道如何继续!我在网上看了很多文章,但仍然没有快乐。
任何帮助将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。