C# 如何正确添加服务引用?
请帮帮我。我创建带有NetCpBinding和安全性的服务C# 如何正确添加服务引用?,c#,.net,wcf,service,nettcpbinding,C#,.net,Wcf,Service,Nettcpbinding,请帮帮我。我创建带有NetCpBinding和安全性的服务mode=“Message”MessageclientCredentialType=“UserName”,这是我的配置 <system.serviceModel> <client> <endpoint address="http://topaznet.hq.eximb.com/RS/Svc/RS.svc" binding="wsHttpBinding" bindingConfiguration
mode=“Message”
MessageclientCredentialType=“UserName”
,这是我的配置
<system.serviceModel>
<client>
<endpoint address="http://topaznet.hq.eximb.com/RS/Svc/RS.svc"
binding="wsHttpBinding" bindingConfiguration="wsHttpBindingEndpoint"
contract="RSClient.IRS" name="wsHttpBindingEndpoint" />
</client>
<services>
<service behaviorConfiguration="CredoServiceBehavior" name="CredoService.Credo">
<endpoint address="" binding="netTcpBinding" name="netTcpBindingEndpoint"
contract="CredoService.ICredo" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" endpointConfiguration="" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/CredoService/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CredoServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CredoService.Common.CustomUserNameValidator, CredoService"/>
<serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="91797E67B20D0853A90CA8E228AF460A382ED94B" />
<windowsAuthentication allowAnonymousLogons="true"/>
</serviceCredentials>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentSessions="2147483647" maxConcurrentInstances="2147483647"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
服务托管在IIS中,工作正常。
我创建了新的windows窗体项目,并单击“添加服务引用”,visual studio genetate作为我的配置:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingEndpoint1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost/CredoService/Credo.svc"
binding="netTcpBinding" bindingConfiguration="netTcpBindingEndpoint"
contract="CredoClient.ICredo" name="netTcpBindingEndpoint">
<identity>
<servicePrincipalName value="host/home" />
</identity>
</endpoint>
</client>
</system.serviceModel>
在此web配置中:
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
但为我服务
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
如果我更改此客户端不工作并引发异常。
如何修复此问题?我刚刚发现您的代码存在另一个问题。您的服务没有选择绑定
<endpoint address="" binding="netTcpBinding" name="netTcpBindingEndpoint"
contract="CredoService.ICredo" />
需要
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" name="netTcpBindingEndpoint" contract="CredoService.ICredo" />
在
部分中
这就解释了为什么VS使用默认NetTcpBinding而不是您的选项。我刚刚发现了您的代码中的另一个问题。您的服务没有选择绑定
<endpoint address="" binding="netTcpBinding" name="netTcpBindingEndpoint"
contract="CredoService.ICredo" />
需要
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" name="netTcpBindingEndpoint" contract="CredoService.ICredo" />
在
部分中
这就解释了为什么VS使用默认NetTcpBinding而不是您的选项。这只是一个代码转储。“不工作”和“抛出异常”是没有意义的。什么不起作用?抛出了什么异常?异常在哪里抛出?您必须帮助我们帮助您。在您的部分:bindingConfiguration=“netTcpBindingEndpoint”@Vadim我的解决方案对您有用吗???你能接受答案或者发表评论让我们知道事情的进展吗?这只是一个代码转储。“不工作”和“抛出异常”是没有意义的。什么不起作用?抛出了什么异常?异常在哪里抛出?您必须帮助我们帮助您。在您的部分:bindingConfiguration=“netTcpBindingEndpoint”@Vadim我的解决方案对您有用吗???你能接受这个答案或者发表评论让我们知道事情的进展吗?