【问题标题】:The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'BasicHTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“基本”
【发布时间】:2018-12-10 23:33:23
【问题描述】:

**当我尝试在身份验证中使用用户名和密码调用 Web 服务时,它给了我 401(身份验证错误),与使用 Soap UI 一样。 我的示例代码和 web.config 仅供参考 在 Soap UI 中,我在属性中传递密码和用户名。 **

ExternalTransferInRequest requestbody = new ExternalTransferInRequest();
    requestbody.referenceTxnId = 123456789101112131;
    requestbody.userName = "5F4aS7QIfS32A4qlCP0BlaEX4qi+lV0p";
    requestbody.password = "1kZ+ZKKNe6zRqot9Qels1g==";
    requestbody.deviceType = 9;
    requestbody.amount = "5000";
    requestbody.mobileAccountNumber = "33319015910";
    requestbody.bankName = "00–Ubank";
    requestbody.bankAccountNumber = "051000207960141";
    ExternalTransferInRequest1 request = new ExternalTransferInRequest1();
    ExternalTransferInResponse resposebody = new ExternalTransferInResponse();
    ExternalTransferInResponse1 response = new ExternalTransferInResponse1();
    //Customer_PortClient proxy = new Customer_PortClient();
    ThirdPartyServicesMiddleWareSoapPortClient c = new ThirdPartyServicesMiddleWareSoapPortClient();
    ThirdPartyServicesMiddleWareSoapPort ts = c;
    c.ClientCredentials.UserName.UserName = "*************";
    c.ClientCredentials.UserName.Password = "********";
    //c.ClientCredentials.UserName.UserName = "smw.tp_services_pibas";
    //c.ClientCredentials.UserName.Password = "Sybase@365";

    response = ts.ExternalTransferIn(request);
    resposebody = response.ExternalTransferInResponse; 

Web.config

 <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="ThirdPartyServicesMiddleWareSoapPortSoap11" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536"
      textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
      messageEncoding="Text">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="Basic" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://**********:8083/mobiliser/thirdpartymw"
    binding="basicHttpBinding" bindingConfiguration="ThirdPartyServicesMiddleWareSoapPortSoap11"
    contract="TransferInSAP.ThirdPartyServicesMiddleWareSoapPort"
    name="ThirdPartyServicesMiddleWareSoapPortSoap11" />
</client>

【问题讨论】:

    标签: c# asp.net wcf soap wsdl


    【解决方案1】:

    我通过使用下面的 web.config 配置解决了这个问题

      <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" proxyCredentialType="None" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
    

    【讨论】:

      猜你喜欢
      • 2011-12-02
      • 1970-01-01
      • 2016-07-15
      • 2021-12-27
      • 1970-01-01
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多