gpt4 book ai didi

c# - 使用 Web 服务 : Client application : C#

转载 作者:太空宇宙 更新时间:2023-11-03 12:09:26 29 4
gpt4 key购买 nike

错误:

"System.ServiceModel.FaultException: InvalidSecurity : error in processing the WS-Security security header" ...

谁能帮忙解决这个问题

   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>

最佳答案

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

关于c# - 使用 Web 服务 : Client application : C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53139255/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com