[英]How Can I resolve WS2007HttpBinding WCF Service Binding in .NET Core Client Application
I dispose a WCF Service Implemented with WCF 4.6.1 Framework containing an Endpoint binded with WS2007HttpBinding.我处理了一个用 WCF 4.6.1 框架实现的 WCF 服务,其中包含一个与 WS2007HttpBinding 绑定的端点。 My purpose is to implement a .NET Core client Side application that calls this service.我的目的是实现一个调用此服务的 .NET Core 客户端应用程序。 When i tried to use CustomBinding, it generates this error :当我尝试使用 CustomBinding 时,它会生成此错误:
System.InvalidOperationException : 'The CustomBinding on the ServiceEndpoint with contract 'IWSTrust13Sync' lacks a TransportBindingElement. System.InvalidOperationException:“具有合同“IWSTrust13Sync”的 ServiceEndpoint 上的 CustomBinding 缺少 TransportBindingElement。 Every binding must have at least one binding element that derives from TransportBindingElement.'每个绑定必须至少有一个从 TransportBindingElement 派生的绑定元素。
public class Program
{
public static void Main(string[] args)
{
Message requestmessage = Message.CreateMessage(
MessageVersion.Soap12WSAddressing10,
"http://test/test",
"This is the body data");
var binding = new CustomBinding();
var endpoint = new EndpointAddress(new Uri("http://servicetest.service.svc"));
var channelFactory = new ChannelFactory<ServiceSTS.IWSTrust13Sync>(binding, endpoint);
var serviceClient = channelFactory.CreateChannel();
var result = serviceClient.Trust13ValidateAsync(requestmessage);
channelFactory.Close();
Console.WriteLine(result.Status);
}
}
Is there a replacement of WS2007HttpBinding in .NET Core ? .NET Core 中是否有 WS2007HttpBinding 的替代品?
Notice that i should not change any things in the service because it is in use by other applications请注意,我不应该更改服务中的任何内容,因为它正在被其他应用程序使用
As the error shows, you lack TransportBindingElement.如错误所示,您缺少 TransportBindingElement。 Binding consists of BingingElement, a custom binding without bingingelement makes no sense. Binding 由 BingingElement 组成,没有 bingingelement 的自定义绑定毫无意义。 If you want to use custom binding , you should add binging element into it.如果要使用自定义绑定,则应在其中添加 binging 元素。
BindingElement[] elements = new BindingElement[]
{
new TextMessageEncodingBindingElement(),
new HttpTransportBindingElement()
};
CustomBinding binding = new CustomBinding(elements);
using (ChannelFactory<ICalculatorService> channelFacoty = new ChannelFactory<ICalculatorService>(binding, new EndpointAddress("http://localhost:4000/calculator")))
{
ICalculatorService cal = channelFacoty.CreateChannel();
Console.WriteLine( cal.Add(1, 3));
Console.Read();
}
But since you are using ws2007httpbinging in server side, why not directly use ws2007httpbinding in your client side.但是既然您在服务器端使用 ws2007httpbinging,为什么不在您的客户端直接使用 ws2007httpbinding。 Using ws2007httpbinging, you needn't add bingingelements into it.(They have been added).使用ws2007httpbinging,不需要在里面添加bingingelements(已经添加了)。
Below is a simple use of ws2007httpbinding.下面是ws2007httpbinding的简单使用。
WS2007HttpBinding binding2 = new WS2007HttpBinding();
using (ChannelFactory<ICalculatorService> channelFacoty = new ChannelFactory<ICalculatorService>(binding2, new EndpointAddress("http://localhost:4000/calculator")))
{
ICalculatorService cal = channelFacoty.CreateChannel();
Console.WriteLine( cal.Add(1, 3));
Console.Read();
}
But if your service side has special configuration of ws2007httpbinging, you had better config your ws2007httpbinging of client side according to its service side configuration.但是如果你的服务端有ws2007httpbinging的特殊配置,你最好根据客户端的服务端配置来配置你的客户端的ws2007httpbinging。
If your service side has publish its metadata, you could add reference to it and directly use the client to call the service.如果你的服务端已经发布了它的元数据,你可以添加对它的引用,直接使用客户端调用服务。 https://www.dotnetforall.com/adding-wcf-service-reference-client/ For svc, the default service metadata address is its address + WSDL, https://www.dotnetforall.com/adding-wcf-service-reference-client/对于svc,默认的服务元数据地址是它的地址+WSDL,
for example , you metadata address is http://servicetest.service.svc?wsdl例如,您的元数据地址是http://servicetest.service.svc?wsdl
You could also use App.config to configure your client.您还可以使用 App.config 来配置您的客户端。
<client>
<endpoint address="http://localhost:4000/calculator" binding="ws2007HttpBinding"
contract="ServiceInterface.ICalculatorService" name="cal" />
</client>
And then , you could directly create the client as follows,然后,您可以直接创建客户端,如下所示,
using (ChannelFactory<ICalculatorService> channelFacoty = new ChannelFactory<ICalculatorService>("cal"))
{
ICalculatorService cal = channelFacoty.CreateChannel();
Console.WriteLine( cal.Add(1, 3));
Console.Read();
}
Please configure your client according to the endpoint configuration of your server side.请根据您服务器端的端点配置配置您的客户端。 Mine is我的是
<service name="Service.CalculatorService" >
<endpoint address="http://localhost:4000/calculator" binding="ws2007HttpBinding" contract="ServiceInterface.ICalculatorService"></endpoint>
</service>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.