Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过代码设置SoapProcessing_C#_Wcf_Binding_Behavior - Fatal编程技术网

C# 如何通过代码设置SoapProcessing

C# 如何通过代码设置SoapProcessing,c#,wcf,binding,behavior,C#,Wcf,Binding,Behavior,我正在尝试禁用端点的SoapProcessing(是的,需要这样做,不要问为什么,消息检查器将无法工作): 然而,我发现的所有文档似乎都依赖于在应用程序的配置文件中设置这个值。我正在为一个不允许包含单独配置文件的应用程序开发插件,因此我必须通过代码设置端点和绑定以及所有这些: // Create transport binding BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWit

我正在尝试禁用端点的SoapProcessing(是的,需要这样做,不要问为什么,消息检查器将无法工作):

然而,我发现的所有文档似乎都依赖于在应用程序的配置文件中设置这个值。我正在为一个不允许包含单独配置文件的应用程序开发插件,因此我必须通过代码设置端点和绑定以及所有这些:

// Create transport binding
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

// Create client
MySyncPortClient _service = new MySyncPortClient(binding, new EndpointAddress("https://path/to/service"));
_service.ClientCredentials.UserName.UserName = "foo";
_service.ClientCredentials.UserName.Password = "bar";

// Set custom bindings
BindingElementCollection elements = _service.Endpoint.Binding.CreateBindingElements();
elements.Find<SecurityBindingElement>().IncludeTimestamp = false;
_service.Endpoint.Binding = new CustomBinding(elements);

// Perform a request
_service.DoSomething();
//创建传输绑定
BasicHttpBinding=新的BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.ClientCredentialType=BasicHttpMessageCredentialType.UserName;
//创建客户端
MySyncPortClient _service=new MySyncPortClient(绑定,新端点地址(“https://path/to/service"));
_service.ClientCredentials.UserName.UserName=“foo”;
_service.ClientCredentials.UserName.Password=“bar”;
//设置自定义绑定
BindingElementCollection元素=_service.Endpoint.Binding.CreateBindingElements();
elements.Find().IncludeTimestamp=false;
_service.Endpoint.Binding=新的CustomBinding(元素);
//执行请求
_服务。DoSomething();

如果有人能给我指出正确的方向,我将不胜感激。不要粗鲁,但请不要建议使用配置文件。它-需要-通过代码完成。如果您需要完整的解释,我可以单独提供。

结束此操作-显然无法完成。

我知道为什么您不能在插件配置文件中完成此操作,但您是否排除在插件插入的应用程序的配置文件中进行更改?好,但是在调用者的配置文件中这样做是允许对每个调用者进行不同配置的原因。您的呼叫者将无法更改配置。我理解,但此插件将作为单个DLL文件部署到一个应用程序中,如果检测到任何更改,该应用程序将自动从服务器下载新的配置文件,因此无法部署/提供单独的配置文件,也无法修改主应用程序的配置文件。这一切都必须通过代码来完成。我仍然不明白这一点。您的配置不应该包含在下载的配置中,以便可以更改并自动下载配置吗?或者他们的配置文件没有使用标准的.NET技术?没有。正如我所说,它必须通过代码来完成。