gpt4 book ai didi

c# - WCF 测试客户端服务调用失败

转载 作者:太空宇宙 更新时间:2023-11-03 14:29:55 26 4
gpt4 key购买 nike

我在使用 ADO.NET iSeries 驱动程序的 c# 应用程序中连接 IBM.Iseries 数据库。我的 WCF 服务将错误抛出为

“HTTP 无法注册 URL http://+:80/Temporary_Listen_Addresses/771be107-8fa3-46f9-ac01-12c4d503d01e/,因为另一个应用程序正在使用 TCP 端口 80。”

 <system.serviceModel>
<client>
<endpoint address="http://localhost:8080/Design_Time_Addresses/DataAccessLayer/POEngine/"
binding="wsDualHttpBinding" bindingConfiguration="" contract="POServiceReference.IPOEngine"
name="MyPoBindings">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://localhost:8080/Design_Time_Addresses/DataAccessLayer/POEngine/"
binding="wsDualHttpBinding" bindingConfiguration="PoBindings1"
contract="POServiceReference.IPOEngine" name="PoBindings">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<bindings>
<wsDualHttpBinding>
<binding name="PoBindings1" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
<wsHttpBinding>
<binding name="PoBindings" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DataAccessLayer.POEngineBehavior"
name="DataAccessLayer.POEngine">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration=""
name="PoBindings" contract="DataAccessLayer.IPOEngine">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Design_Time_Addresses/DataAccessLayer/POEngine/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DataAccessLayer.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="DataAccessLayer.POEngineBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors> </system.serviceModel>

在不使用任何 IBM 数据访问的情况下也有问题。正常的 Hello World 也抛出错误。我需要更改端口地址的地方

最佳答案

“问题”是您正在使用 wsDualHttpBinding,用于双工契约(Contract)(服务器回调给客户端)。你需要这个功能吗?如果这样做,您将需要通过在绑定(bind)配置中指定 clientBaseAddress 来为其提供一个供客户端监听的地址。此外,您需要告知端点使用 PoBindings1 绑定(bind)配置。

WCF 会自动将 GUID 附加到基地址,以确保它生成唯一的终结点地址,但当然它需要一个可以监听的端口号。参见 this MSDN page有关配置部分的文档。它应该大致如下所示:

<system.serviceModel>
<!-- client section omitted -->
<bindings>
<wsDualHttpBinding>
<binding name="PoBindings1"
clientBaseAddress="http://localhost:8080/Callbacks/">
<!-- extra config elements and attributes omitted -->
</binding>
</wsDualHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DataAccessLayer.POEngineBehavior"
name="DataAccessLayer.POEngine">
<endpoint address=""
binding="wsDualHttpBinding"
bindingConfiguration="PoBindings1"
name="PoBindings" contract="DataAccessLayer.IPOEngine">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Design_Time_Addresses/DataAccessLayer/POEngine/" />
</baseAddresses>
</host>
</service>
</services>
<!-- behaviors omitted -->
</system.serviceModel>

如果您使用双工契约(Contract),这就是服务契约(Contract)通常的样子:

[ServiceContract(CallbackContract = typeof(IMyCallbackContract))]
interface IMyContract
{
[OperationContract]
void DoSomething();
}

interface IMyCallbackContract
{
[OperationContract]
void OnCallback();
}

如果您不需要回调功能,您应该使用 WSHttpBinding,或其他“简单”绑定(bind)之一。 Here是 WCF 附带的绑定(bind)类型列表。

关于c# - WCF 测试客户端服务调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2904840/

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