gpt4 book ai didi

c# - app.config 中具有 WCF 无效契约(Contract)属性的脚本组件

转载 作者:行者123 更新时间:2023-11-30 23:12:32 26 4
gpt4 key购买 nike

我正在尝试使用此样板方法中对我的 WSDL 文件的服务引用来配置脚本组件。

public override void CreateNewOutputRows()
{
//create instance of service client

}

但是我遇到了配置文件 app.config 的问题,它提示契约(Contract)属性无效 contract="ServiceReference1.IClientService1所有手动更改此设置的尝试都失败了。类似的帖子建议使用完全限定的名称 Service.MyService 但到目前为止我没有取得任何成功。有没有办法以编程方式指定绑定(bind)?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IClientService1">
<security mode="Transport" />
</binding>
<binding name="BasicHttpBinding_IClientService11" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://server/services/ClientService1.svc/soap"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientService1"
contract="ServiceReference1.IClientService1" name="BasicHttpBinding_IClientService1" />
</client>
</system.serviceModel>
</configuration>

stub 代码如下所示

 public override void CreateNewOutputRows()
{
string endpoint = "https://server/services/ClientService1.svc";
ClientService1Client client = new ClientService1Client(endpoint);
client.ClientCredentials.UserName.UserName = "";
client.ClientCredentials.UserName.Password = "";
Output0Buffer.name = client.GetActiveClients()[1].name.ToString();
}

最佳答案

我认为您的问题可能是由于您的端点地址中包含 /soap

<endpoint address="https://server/services/ClientService1.svc/soap"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientService1"
contract="ServiceReference1.IClientService1" name="BasicHttpBinding_IClientService1" />

我认为应该是:

address="https://server/services/ClientService1.svc"

至于以编程方式创建绑定(bind),这应该可行或让您入门:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
EndpointAddress address = new EndpointAddress("https://server/services/ClientService1.svc");
ClientService1Client client = new ClientService1Client(binding, address);

关于c# - app.config 中具有 WCF 无效契约(Contract)属性的脚本组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44051012/

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