如何使用C#/UWP从app.config选择Soap客户端配置?
我正在尝试将Soap客户端配置放入app.config。但我仍然面临一些问题 这是我的app.config如何使用C#/UWP从app.config选择Soap客户端配置?,c#,wcf,uwp,soap-client,C#,Wcf,Uwp,Soap Client,我正在尝试将Soap客户端配置放入app.config。但我仍然面临一些问题 这是我的app.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyServiceHttpSoapBinding" maxReceivedMessageSize="20000000">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
<basicHttpsBinding>
<binding name="MyServiceHttpsSoapBinding" maxReceivedMessageSize="20000000">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/webservice/MyService"
binding="basicHttpBinding" bindingConfiguration="MyServiceHttpSoapBinding"
contract="MyServiceReference.MyService" name="MyServiceHttpPort" />
<endpoint address="https://localhost:8080/webservice/MyService"
binding="basicHttpsBinding" bindingConfiguration="MyServiceHttpsSoapBinding"
contract="MyServiceReference.MyService" name="MyServiceHttpsPort" />
</client>
</system.serviceModel>
</configuration>
通过调试器,我发现客户端的端点地址为“”,绑定为basicHttpBinding。
但是名称只是“MyServicePort”而不是“MyServiceHttpPort”,并且没有使用绑定配置“MyServiceHttpSoapBinding”。所以它不起作用,因为绑定的安全设置没有设置
我想我可以用newmyserviceclient(“MyServiceHttpPort”)创建客户机代码>,但该构造函数选项不可用
以前它使用编码配置:
client.Endpoint.Address = new EndpointAddress(EndPoint);
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
client.Endpoint.Binding = binding;
但是我更喜欢通过配置来实现。当您在UWP中使用WCF时,您实际上正在使用
是Windows NETFramework的.NETFramework版本的子集,目前支持Windows 8.1商店应用程序可用的API接口。它用于构建.NET核心应用程序,包括和。这些客户端库适合移动设备或中端服务器与现有WCF服务通信
与.NET Framework版本不同,现在在.NET Core中对WCF的所有配置都是在代码中完成的-没有配置文件。有关更多信息,请参阅和
因此,在UWP应用程序中,我们无法使用配置文件配置客户端,我们需要以编程方式执行此操作。仍然是这样吗?因为我使用WCF从头制作了一个UWP应用程序,我找不到任何服务参考的配置。
client.Endpoint.Address = new EndpointAddress(EndPoint);
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
client.Endpoint.Binding = binding;