如何使用自定义绑定从非托管c++连接到WCF服务
How to connect to a WCF service with Custom Binding from unmanaged C++
我需要从本地c++应用程序连接到WCF服务。我尝试了下面的链接,它与wsHttpBinding
一起工作。
为非托管c++客户端创建WCF服务
然而,我需要用自定义绑定连接到WCF服务。这就是自定义绑定代码在我的应用配置文件
中的样子<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="ResourceCenterEndpoint5">
<mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Default" maxBufferSize="65536" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</mtomMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Ntlm"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536"
proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</binding>
</bindings>
<client>
<endpoint address="http://usaabcxyzas1.na.abc.com/Build15/ReserSVC/Resource.svc"
binding="customBinding" bindingConfiguration="ResourceCenterEndpoint5"
contract="ServiceReference2.ResourceCenterServiceContract"
name="ResourceCenterEndpoint5">
<identity>
<userPrincipalName value="devlts_srv@na.abc.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
我有一个桥DLL,这是一个托管的c++ DLL。托管的c++ DLL将c#客户端连接到本机应用程序。但是,我无法从托管的c++ DLL连接到Web服务,因为Web服务正在使用自定义绑定。我得到的错误是:
http请求未经授权,客户端身份验证方案为"匿名"。从服务器接收到的认证头是'Negotiate,NTLM'
这是我试图从托管c++ dll连接到web服务的方式:
Binding^ binding = gcnew BasicHttpBinding();
EndpointAddress^ address = gcnew EndpointAddress(gcnew String("http://usaabcxyzas1.na.abc.com/Build15/ReserSVC/Resource.svc"));
HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient^ client = gcnew HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient(binding, address);
client->DoWork();
所以基本上我需要用自定义绑定将托管c++ dll连接到WCF服务。我该怎么做呢?
你试图在客户端代码中使用BasicHttpBinding
在配置文件中你需要NTLM:
authenticationScheme="Ntlm"
错误指向你在服务配置文件中所拥有的内容。
*The http request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the sever was 'Negotiate,NTLM'*
你看起来也像试图入侵
proxyAuthenticationScheme="Anonymous"
所以这取决于您的安全需求。如果您希望服务不具有安全性,只需取出NTLM引用。如果需要安全性,则需要在绑定定义中加入security部分,类似于:
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
查看这篇文章了解更多
我不认为你想要自定义绑定,就像你想自定义开箱即用的绑定一样。除非你的意图是创建一个专有的通信协议,在TCP/IP等之外。
对于安全性问题,您可能希望查看设置security。模式属性,以及分配正确的传输和/或消息安全属性。如。使用证书或密码挑战,加密,加密和签名等
您还需要在客户端执行相同的操作。该绑定应该与服务器端的绑定几乎相同。
如果你不喜欢基本的http,还有TCP, MSMQ,命名管道等等。
您是否尝试过使用SvcUtil从web服务生成WSDL ?一旦您有了客户端代理和配置,它将具有客户端连接到服务所需的配置。
你也提到你想使用CustomBinding连接,但在客户端代码中你使用的是BasicHttpBinding。
你需要你的代码设置的另一件事是AuthenticationScheme,因为服务器期望方案NTLM,而你的客户端代码没有设置,默认情况下它是匿名的
这看起来像是一个身份验证错误,所以你需要给自己更多的权限或找出谁得到它,但例如提供用户名和密码。
我维护使用Wcf服务的本地c++应用程序。与其处理原始连接和XML,我建议使用优秀的gSoap库。这将从服务中获取WSDL,并生成使用它进行操作的代码。通过使用http://code.google.com/p/gsoapwininet/插件,所有的通信都是通过IE进行的,这意味着所有各种windows身份验证方法都是自动支持的,这应该可以解决您的特定问题。
您可以创建一个customBinding并传入所需的绑定配置名称。
- 当套接字连接断开时检测C/C++Unix
- 无法在windows上使用mingw将sqlite3与c连接
- 到连接组件算法的问题(递归)
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 无法在C++中建立与MySQL数据库的连接
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 使用 bfs 解决连接组件问题时得到错误的答案
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 如何修复valgrind启动时的致命错误(与libc6-dbg和libc6-dbg:i386连接)
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- OSX蓝牙打开RFCOMMChannelAsync声称已连接,但未建立连接,并且从未调用过委托
- 在 libcurl 连接池中预创建连接
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- libcurl 和 DNS ttl 中的内部连接管理
- 如何应用 libcurl 的持久连接选项
- 提升 ASIO - io_service 不要等待连接到线程
- WinSock2:connect() 提供"连接被拒绝"
- 升压信号2将插槽传递到成员功能以断开连接