C# 如何通过自定义绑定从非托管C+连接到WCF服务+; 我需要从本地C++应用程序连接到WCF服务。我尝试了下面的链接,它使用了wsHttpBinding
但是,我需要使用自定义绑定连接到WCF服务。这就是自定义绑定的代码在我的应用程序配置文件中的样子C# 如何通过自定义绑定从非托管C+连接到WCF服务+; 我需要从本地C++应用程序连接到WCF服务。我尝试了下面的链接,它使用了wsHttpBinding,c#,c++,wcf,c++-cli,C#,C++,Wcf,C++ Cli,但是,我需要使用自定义绑定连接到WCF服务。这就是自定义绑定的代码在我的应用程序配置文件中的样子 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <customBinding> <binding name="ResourceCenterEndpoint5">
<?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>
基本上,我需要将托管C++ DLL与WCF服务连接,并使用自定义绑定。如何执行此操作?您可以创建customBinding并传入所需的绑定配置名称 我认为您不需要定制绑定,而需要定制现成的绑定。除非您打算在TCP/IP等协议之外创建一个适当的通信协议 对于安全问题,您需要研究设置security.Mode属性以及分配正确的传输和/或消息安全属性。例如,使用证书或密码挑战、加密、加密和签名等 您还需要在客户端执行同样的操作。绑定应该与服务器端的绑定几乎相同
如果您不喜欢basicHttp,那么总会有TCP、MSMQ、namedpiped等等。您应该查找它以获得完整列表。您是否尝试使用SvcUtil从web服务生成WSDL。一旦您有了客户端代理和配置,它将具有客户端连接到服务所需的配置 您还提到您希望使用CustomBinding进行连接,但在客户机代码中您使用的是BasicHttpBinding
您需要设置的另一个代码是AuthenticationScheme,因为服务器需要scheme NTLM,而您的客户端代码没有设置,默认情况下它是匿名的。我觉得这像是身份验证错误,因此,您需要OTO给自己更多的权限或找出谁来获取它,但例如提供用户名和密码。 < P>我维护消耗WCF服务的本机C++应用程序。我建议使用优秀的gSoap库,而不是处理原始连接和XML。这将从服务中获取WSDL并生成代码以使用它进行操作。通过使用插件,所有通信都是通过IE进行的,这意味着所有各种windows身份验证方法都将自动得到支持,这将解决您的特定问题。您正在尝试在客户端代码中使用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 mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
看
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>