我正在尝试将项目从.net转移到.net核心。我最初是在.net中使用WCF WSHttpBinding服务,但是在.net核心中我无法使用相同的服务。我尝试使用BasicHttpBinding在客户端与WsHttpBinding进行连接,但是它抛出一个错误,表明绑定应该在客户端和服务器端都匹配。
建议如何在不进行修改的情况下在.Net Core上实现WSHttpBinding 客户端上的WSHttpBindings。
答案 0 :(得分:3)
.net core 2.1中尚不支持WCF WSHttpBinding。 这是.Net core中受支持的绑定的列表
详细了解受支持的功能click here
答案 1 :(得分:1)
我在完整框架上使用了WSHttpBinding。迁移到.net core 2.2之后,我遇到了同样的问题。
后来我发现BasicHttpsBinding(它是https,而不是http)非常适合我的需求。我简单地用BasicHttpsBinding替换了WSHttpBinding,并且一切正常(在Windows和Linux上)。
答案 2 :(得分:0)
这是一个更完整的答案,可能会对尝试使用.NET Core(.NET Core 2.2)调用SOAP服务终结点并正在努力使其正常工作的人有所帮助。
对于这个答案,我假设您已经添加了一个Connected Service。如果没有,请参考此Microsoft Article
下面的示例使用一个BasicHttpBinding
凭据类型(DOMAIN \ Username)的Ntlm
:
public async Task<string> AddNAVSalesOrder(string jsonString)
{
var binding = new BasicHttpsBinding();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
var endpoint = new EndpointAddress(_appConfig["NAVEndpoint"]);
var client = new eCommIntegrationMgt_PortClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = _appConfig["NAVUsername"];
client.ClientCredentials.UserName.Password = _appConfig["NAVPassword"];
try
{
var result = await client.ImportSalesOrderAsync(jsonString);
return result.return_value;
}
catch (Exception)
{
throw;
}
}
_appConfig
是一个全局变量,可以通过DI(依赖注入)使用。如果不使用DI,则可以用硬编码值替换它们。 catch
在这里是多余的,但是您可以添加自定义错误处理/记录。
eCommIntegrationMgt_PortClient
是客户端,即我们所有端点都存在的Service对象。
答案 3 :(得分:0)
我能够使用自定义绑定使其工作。还可以配置https,文本和二进制绑定元素。
var binding = new CustomBinding
{
Elements = { new HttpTransportBindingElement
{
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue
}}
};
答案 4 :(得分:0)
这是我用过的代码片段
var binding = GetCustomBinding();
private Binding GetCustomBinding()
{
CustomBinding result = new CustomBinding();
TextMessageEncodingBindingElement textBindingElement = new TextMessageEncodingBindingElement();
result.Elements.Add(textBindingElement);
HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement
{
AllowCookies = true,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
AuthenticationScheme = System.Net.AuthenticationSchemes.Negotiate
};
result.Elements.Add(httpsBindingElement);
return result;
}
答案 5 :(得分:0)
.Net Core 尚不支持 WsHttpBinding。 你可以试试这个。 https://www.nuget.org/packages/WsSecurityCore/
您可以获得 XmlNodeList 或 Xml 完整字符串形式的响应,并使用 XmlSerializer 转换为您的类的响应。