我在Visual Studio中使用“Add->;service reference”导入了SOAP服务。这会生成大量代码,有助于使用服务。
SOAP必须使用应用程序为每个不同的客户群调用不同的端点。一些端点采用纯HTTP,其他端点采用HTTPS。(都在内部网络上,所以HTTP不是什么大事)。每个HTTP端点都可以正常工作,每个HTTPS端点都可以工作,但应用程序不能同时支持这两个端点。
此配置支持HTTPS:
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) { if ((endpointConfiguration == EndpointConfiguration.ServiceV201209Soap)) { System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(); result.Security.Mode = BasicHttpSecurityMode.Transport; result.MaxBufferSize = int.MaxValue; result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; result.MaxReceivedMessageSize = int.MaxValue; result.AllowCookies = true; return result; } throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); }
删除“Security.Mode”将支持HTTP。
我在模式之间切换时遇到问题。我能做的最好的是检查端点是HTTP还是HTTPS,更改绑定配置,但这使得它只能在切换端点后的第二次调用中工作。那太可怕了,所以我放弃了。
是否有一种简单的配置可以同时支持这两种配置?