【问题标题】:Consuming Webservice : Client application : C#使用 Web 服务:客户端应用程序:C#
【发布时间】:2018-11-04 09:13:40
【问题描述】:

错误:

“System.ServiceModel.FaultException: InvalidSecurity: 错误 处理 WS-Security 安全标头” ...

谁能帮忙解决这个问题

   public void CallServiceMNB()
        {
            ServiceReference1.SOAPCLIENT objMNB = new ServiceReference1.SOAPCLIENT();
            ServiceReference1.SOAPCLIENTinput input = new ServiceReference1.SOAPCLIENTinput();
            string Username = "xxx";
            string Password = "xxxx";
            objMNB.ClientCredentials.UserName.UserName = Username;
            objMNB.ClientCredentials.UserName.Password = Password;
            input.p_FROM_DATE = "01-01-2018";
            input.p_JE_CATEGORY = "xxxx";
            input.p_GROUP_ID = "";
            input.p_JE_SOURCE = "YYYYYY";
            input.p_LEDGER_NAME = "YYYYY";
            input.p_TO_DATE = "31-12-2018";
            try
            {
                objMNB.Open();
                objMNB.GetGLDetails(input);
                objMNB.Close();
            }
            catch (Exception Ex)
            {
                this.richTextBox1.Text = Ex.ToString();
                objMNB.Close();
            }
        }


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
    <system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="YYYYYY">
                    <!--    WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'http://gl.ws.apps.oracle.xxdof/':    -->
                    <!--    <wsdl:binding name='YYYYYY'>    -->
                    <!--        <sp:SupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">..</sp:SupportingTokens> -->




                    <textMessageEncoding messageVersion="Soap11" />
                    <httpsTransport />


                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="https://XXXXX"
                binding="customBinding" bindingConfiguration="YYYYYY"
                contract="ServiceReference1.SOAPCLIENT" name="SOAPCLIENT" />
        </client>
    </system.serviceModel>
</configuration>

【问题讨论】:

  • 是的,霍尔特曼先生...我提供了上述代码和正确的用户名和密码!!我得到了使用 SOAPUI(smartbear) 的结果。在 C# 中面临安全问题。是否需要添加任何参考?请帮忙
  • 您离一个可以回答的问题越来越近了。好像是WCF,你应该加上那个标签。
  • 完整的异常文本可能会有所帮助。并发布 WCF 配置。 C# 部分看起来不错,但大多数 WCF 发生在 app.config 中。
  • 不是霍尔特曼先生。我没有使用 WCF,只是使用网站来使用 SOAP Webservice。
  • 我看到了很多 WCF...而且“WsdlImporter 遇到无法识别的策略断言”可能是您问题的开始。

标签: c# wcf soap ws-security


【解决方案1】:

客户端凭据取决于您在服务器上托管的自定义绑定中创建的 SecurityBindingElement。
https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.channels.securitybindingelement?view=netframework-4.7.2
您应该根据自定义绑定的身份验证安全模式将令牌添加到安全头中。
BasicHttpBinding默认不需要提供凭证,而我们需要在Wshttpbinding中默认提供Windows账号。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/programming-wcf-security

【讨论】:

    猜你喜欢
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2010-11-10
    相关资源
    最近更新 更多