【发布时间】:2023-03-21 16:05:01
【问题描述】:
我坚持实现以前在 app.config 中定义的 BasicHTTPBinding(在类库中不存在)。我希望这些设置是预定义的,因此可以在我的 .dll 中进行硬编码。
这是我的 app.config 所说的:
<!-- language: xaml -->
<bindings>
<basicHttpBinding>
<binding name="ImageServerServiceSoapBinding" messageEncoding="Mtom" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xx.xx.xx.xx:xx/xyz" binding="basicHttpBinding" bindingConfiguration="ImageServerServiceSoapBinding" contract="xyz.ImageServer" name="ImageServerPort"/>
</client>
我开始以编程方式设置绑定,但由于我的 _binding 中没有在 app.config 中设置的方法而卡住了?!
<!-- language: c# -->
System.ServiceModel.Channels.Binding _binding = new System.ServiceModel.BasicHttpBinding();
System.ServiceModel.EndpointAddress _address = new System.ServiceModel.EndpointAddress(@"http://xx.xx.xx.xx:xxx/xyz");
_binding.Name = "ImageServerServiceSoapBinding";
_binding.CloseTimeout = new TimeSpan(0, 1, 0);
_binding.OpenTimeout = new TimeSpan(0, 1, 0);
_binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
_binding.SendTimeout = new TimeSpan(0, 1, 0);
this._Client = new ImageServerClient(_binding, _address);
_Settings.TraverseData.TraverseWidth = double.Parse(_Client.getCameraInfo(d2els_selectedcam).traverseLength);
由于从绑定到客户端 (text/xml; charset=utf-8) 的内容类型 (multipart/related;) 不兼容,最后一行失败?!
如何访问 BasicHTTPBinding 中的这些设置?还是我有错误的概念?
_binding.maxDepth // ... etc.
不是 BasicHTTPBinding 的成员。
【问题讨论】: