使用Web服务:客户端应用程序:C#
错误: “System.ServiceModel.FaultException:InvalidSecurity:中出错” 正在处理WS-Security安全标头“ 有人能在这个问题上帮忙吗使用Web服务:客户端应用程序:C#,c#,wcf,soap,ws-security,C#,Wcf,Soap,Ws Security,错误: “System.ServiceModel.FaultException:InvalidSecurity:中出错” 正在处理WS-Security安全标头“ 有人能在这个问题上帮忙吗 public void CallServiceMNB() { ServiceReference1.SOAPCLIENT objMNB = new ServiceReference1.SOAPCLIENT(); ServiceReferenc
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>
public void CallServiceMNB()
{
ServiceReference1.SOAPCLIENT objMNB=新的ServiceReference1.SOAPCLIENT();
ServiceReference1.SOAPCLIENTinput输入=新的ServiceReference1.SOAPCLIENTinput();
字符串Username=“xxx”;
字符串密码=“xxxx”;
objMNB.ClientCredentials.UserName.UserName=用户名;
objMNB.ClientCredentials.UserName.Password=密码;
输入日期为2018年1月1日的p;
输入.p_JE_CATEGORY=“xxxx”;
input.p_GROUP_ID=“”;
input.p_JE_SOURCE=“YYYYYY”;
input.p_分类账_NAME=“YYYYY”;
输入日期:2018年12月31日;
尝试
{
objMNB.Open();
objMNB.GetGLDetails(输入);
objMNB.Close();
}
捕获(例外情况除外)
{
this.richTextBox1.Text=Ex.ToString();
objMNB.Close();
}
}
客户端凭据取决于在服务器上的自定义绑定宿主中创建的SecurityBindingElement。您应该根据自定义绑定的身份验证安全模式向安全标头添加令牌。
对于BasicHttpBinding,默认情况下您不需要提供凭据,而我们需要在Wshttpbinding中默认提供Windows帐户。
是的,霍特曼先生。。。我提供了上述代码和正确的用户名和密码!!我在使用SOAPUI(smartbear)时得到了结果。在C#中,面临安全问题。是否需要添加任何参考资料???请帮助您接近一个可回答的问题。似乎是WCF,您应该添加该标记。完整的异常文本可能会有所帮助。并发布WCF配置。C#部分看起来不错,但大多数WCF发生在app.config中。没有霍特曼先生。我没有使用WCF,只是使用一个网站来使用SOAP Web服务。不过我看到了很多WCF。。。“WsdlImporter遇到无法识别的策略断言”可能是问题的开始。