gpt4 book ai didi

c# - 无法在 WCF ServiceModel 客户端配置部分中找到元素

转载 作者:太空宇宙 更新时间:2023-11-03 13:07:19 24 4
gpt4 key购买 nike

[ServiceContract]
public interface IService1
{
[OperationContract]
DataTable GetADUserList(string strUserName, string strFirstName, string strLastName, string strEmail, string domain);
}

我有一个 WCF 服务托管在 IIS 中,上面有示例服务契约(Contract)。服务 web.config 文件设置如下。

完整的 WCF Web.config 文件

 <?xml version="1.0"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>

<bindings>
<customBinding>
<binding name="notSecureBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
<binding name="SecureBinding">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>

<client>
<endpoint address="http://ServerName.myDomain.org/ADSearcher/Service1.svc"
binding="customBinding"
bindingConfiguration="notSecureBinding"
contract="ADSearcher.IService1"
name="notSecureBinding" />

<endpoint address="http://ServerName.myDomain.org/ADSearcher/Service1.svc"
binding="customBinding"
bindingConfiguration="SecureBinding"
contract="ADSearcher.IService1"
name="SecureBinding" />
</client>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

</system.serviceModel>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>

我正在尝试以编程方式访问该服务,如下所示。

  EndpointAddress endpointAddress = new EndpointAddress("http://ServerName.myDomain.org/ADSearcher/Service1.svc");
IService1 ADUser = new ChannelFactory<IService1>("notSecureBinding", endpointAddress).CreateChannel();

上面的代码抛出了下面的错误

Could not find endpoint element with name 'notSecureBinding' and contract 'ADSearcher.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element

我似乎无法弄清楚我在这里做错了什么,或者是否有更好的替代方法以编程方式访问此服务?

最佳答案

在您的端点中,您指定了 Data.GetData 类型的契约(Contract)。协定类型为IService1,默认情况下,协定名称应为服务接口(interface)的类型名称。

如果您确实希望将您的IService 称为Data.GetData,您可以通过ServiceContractAttribute 指定标识名称:

[ServiceContract(ConfigurationName = "Data.GetData")]
public interface IService1
{
[OperationContract]
DataTable GetADUserList(string strUserName, string strFirstName, string strLastName, string strEmail, string domain);
}

关于c# - 无法在 WCF ServiceModel 客户端配置部分中找到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30320441/

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