通过生成的 WebServiceClient 进行 WCF Soap 基本身份验证
我正在尝试使用 WCF Web 服务参考来使用 SOAP Web 服务。
我已经能够使用 System.Web.Servicees Web 服务参考在 .NET 4.8 框架项目中成功使用 SOAP Web 服务。但是我需要在 .NET Core 项目中使用 Web 服务。从 WSDL 生成的 WCF 类与 .NET Framework Web 服务不同。看来您现在必须使用生成的 WebServiceClient 来与 Web 服务交互。
我相信 Web 服务需要基本身份验证,因为我能够在 .NET Framework 项目中使用基本身份验证进行身份验证。
这是当我尝试执行 Web 服务的方法之一时收到的错误消息。
System.ServiceModel.Security.MessageSecurityException
HResult=0x80131500
Message=The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
Source=System.Private.ServiceModel
这是我的代码,它实例化客户端并调用方法“
var callContext = new CAdxCallContext();
callContext.codeLang = "ENG";
callContext.poolAlias = "BGRTEST";
callContext.requestConfig = "adxwss.trace.on=on&adxwss.trace.size=16384&adonix.trace.on=on&adonix.trace.level=3&adonix.trace.size=8";
var proxy = new CAdxWebServiceXmlCCClient();
proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "password";
string _InputXml = "<PARAM>" +
"<GRP ID= \"GRP1\">" +
"<FLD NAME = \"ITMREF\">" + 100001 + "</FLD>" +
"</GRP>" +
"</PARAM>";
try
{
var response = proxy.run(callContext, "BGR_SIEPRO", _InputXml);
}
finally
{
proxy.Close();
}
我的 WCF 服务连接”: WCF 连接服务屏幕截图
自动生成的 WCF WebServiceClient:https://github.com/abiddle-bgr/Test/blob/main/CAdxWebServiceXmlCCClient.cs
I'm attempting to consume a SOAP Webservice using a WCF Web Service Reference.
I have been able to successfully consume the SOAP web service in a .NET 4.8 framework project using the System.Web.Servicees Web Service Reference. However I need to consume the web service in a .NET Core project. The WCF generated class from the WSDL is different than the .NET framework web service. It seems like you now have to use the generated WebServiceClient to interact with the web service.
I believe the web service requires basic authentication as I was able to authenticate using basic authentication in the .NET framework project.
Here is the error message I'm getting when I try to execute one of the web service's methods.
System.ServiceModel.Security.MessageSecurityException
HResult=0x80131500
Message=The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
Source=System.Private.ServiceModel
Here is my code which instantiates the client and calls the method
var callContext = new CAdxCallContext();
callContext.codeLang = "ENG";
callContext.poolAlias = "BGRTEST";
callContext.requestConfig = "adxwss.trace.on=on&adxwss.trace.size=16384&adonix.trace.on=on&adonix.trace.level=3&adonix.trace.size=8";
var proxy = new CAdxWebServiceXmlCCClient();
proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "password";
string _InputXml = "<PARAM>" +
"<GRP ID= \"GRP1\">" +
"<FLD NAME = \"ITMREF\">" + 100001 + "</FLD>" +
"</GRP>" +
"</PARAM>";
try
{
var response = proxy.run(callContext, "BGR_SIEPRO", _InputXml);
}
finally
{
proxy.Close();
}
My WCF service connection:
WCF Connected Service Screenshot
The Auto-generated WCF WebServiceClient: https://github.com/abiddle-bgr/Test/blob/main/CAdxWebServiceXmlCCClient.cs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终不得不通过创建自定义端点并将其作为自定义端点行为添加到代理来手动注入标头。
I ended up having to manually inject the headers by creating a custom endpoint and adding it to the proxy as a custom endpoint behavior.
您是否设置了安全传输模式?与此类似: WCF客户端中的基本身份验证。
在代码中,设置代理类允许模拟
可以看这篇文章。
Did you set secure transfer mode? similar to this: Basic Authentication in WCF client.
In the code, set the proxy class to allow impersonation
You can look at this post.