相关疑难解决方法(0)

WCF:如何从配置中获取绑定对象

我想从web.config或app.config获取Binding对象.

所以,这段代码有效:

wcfTestClient = new TestServiceClient("my_endpoint", Url + "/TestService.svc");
Run Code Online (Sandbox Code Playgroud)

但我想做以下事情:

Binding binding = DoSomething();
wcfTestClient = new TestServiceClient(binding, Url + "/TestService.svc");
Run Code Online (Sandbox Code Playgroud)

当然,我对DoSomething()方法感兴趣.

.net wcf wcf-binding

16
推荐指数
5
解决办法
2万
查看次数

WCF TransportCredentialOnly不发送用户名和密码

我有以下WCF客户端配置:

<basicHttpBinding>
   <binding name="basicHttpOCCWS" closeTimeout="00:01:00" openTimeout="00:01:00"
                 receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="100000000" maxBufferPoolSize="524288"
                 maxReceivedMessageSize="100000000" messageEncoding="Text"
                 textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192"
                    maxArrayLength="16384" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <security mode="TransportCredentialOnly">
         <transport clientCredentialType="Basic" />            
      </security>
   </binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)

在代码中,我按如下方式设置用户名和密码:

client.ClientCredentials.UserName.UserName = _cacledUserId;
client.ClientCredentials.UserName.Password = _cachedPassword;
Run Code Online (Sandbox Code Playgroud)

但是,在Tomcat上运行的Web服务返回错误:

"在安全上下文中找不到身份验证对象."

当我查看HTTP标头时,它缺少凭据信息,如下所示:

POST /occ600webservice/services/OCC_WS HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8; action=""
Host: 192.54.173.130:8080
Content-Length: 2223
Expect: 100-continue 
Run Code Online (Sandbox Code Playgroud)

为什么我的凭据没有被发送?

TIA.

克劳斯

wcf

9
推荐指数
1
解决办法
8806
查看次数

如何在 WCF 客户端中提供用户名和客户端证书(为什么此示例有效)?

考虑一个 WCF 服务,其目的是让传输层需要客户端证书(客户端证书在 IIS 中设置为“必需”)。同样,消息层也会有用户名认证。

现在我已经看到这个问题了:

禁止 WCF 客户端证书和用户名凭据

我可以在某种程度上理解那里发生的事情,并意识到 WCF 本质上不允许两者兼而有之。我在代码中执行了与上面引用的链接中的海报相同的步骤,并发现了相同的结果...正在传递消息级用户名凭据(在我的例子中是在 SOAP 标头中),但是客户端证书(尽管是在 VS 调试中查看请求客户端时附加)实际上并未由端点处理。

现在是让我感到困惑的部分。我决定对它进行一些破解。我想知道为什么它的工作原理与我想要的完全一样......它通过了 IIS 客户端证书要求,用户名被传递到 WCF 服务并且一切正常。然而,WCF 不允许我仅使用 WCF 配置文件或代码(我可以找到)来完成此操作。为什么?

            // sets up a proxy client based on endpoint config
            // basically just here to get the URL.
            this.InitializeSubmitClient();

            // these get used to create the HttpWebRequest
            string url = this.submitClient.Endpoint.Address.ToString();
            string action = "SubmitCDA";

            // this deserializes an XML file which is the "shell" of SOAP document and inject username/password into SOAP Security node …
Run Code Online (Sandbox Code Playgroud)

c# ssl wcf soap

1
推荐指数
1
解决办法
2001
查看次数

标签 统计

wcf ×3

.net ×1

c# ×1

soap ×1

ssl ×1

wcf-binding ×1