gpt4 book ai didi

c# - WCF 动态绑定(bind) - 如何指定端点?

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:35 25 4
gpt4 key购买 nike

我正在尝试使用代码而不是 app.config 来绑定(bind)我的 WCF 客户端,因为我需要为不同的部署更改主机 IP 地址。

这是我的 app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICX" maxReceivedMessageSize="1073741824" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1/CX/CX.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICX" contract="CXService.ICX" name="WSHttpBinding_ICX">
<identity>
<servicePrincipalName value="host/SilverStar" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>

这是我的代码:

public static void StartUp()
{
XmlDictionaryReaderQuotas quota = new XmlDictionaryReaderQuotas();
quota.MaxArrayLength = 2147483647;
quota.MaxBytesPerRead = 2147483647;
quota.MaxDepth = 2147483647;
quota.MaxNameTableCharCount = 2147483647;
quota.MaxStringContentLength = 2147483647;
EndpointAddress addr = new EndpointAddress(new Uri("http://127.0.0.1/CX/CX.svc"));

WSHttpBinding binding1 = new WSHttpBinding();
binding1.Name = "WSHttpBinding_ICX";
binding1.MaxReceivedMessageSize = 1073741824;
binding1.ReaderQuotas = quota;

// Globals.CXClient is the client object
Globals.CXClient = new CXService.CXClient(binding1, addr);

// This line does not compile! Endpoint is read-only!!
Globals.CXClient.Endpoint = new ServiceEndpoint(new ContractDescription("CXService.ICX"), (Binding)binding1, addr);
}

最后一行代码无法编译,因为 .EndPoint 是只读属性。

请帮忙。

最佳答案

试试这个:

Globals.CXClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("your url here");

关于c# - WCF 动态绑定(bind) - 如何指定端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44037748/

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