winform + wcf (netTcpBinding) 양 방향 통신 사용자 정의 사용자 이름 암호 검증
vs 명령 으로 만 들 기
makecert.exe -sr LocalMachine -ss My -a sha1 -n CN=TestServer -sky exchange -pe
인증서 만 들 기 세부 정보http://blog.csdn.net/aojiancc2/article/details/17711925
wcf 서버 쪽
namespace WcfCertificate
{
// : “ ” “ ” , “ITcpCer”。
[ServiceContract(CallbackContract = typeof(ICallback))]// UserCallBack
public interface ITcpCer
{
[OperationContract]
void DoWork();
}
public interface ICallback //
{
[OperationContract(IsOneWay = true)]// ,
void TestCallBack(string hello);
}
}
namespace WcfCertificate
{
// : “ ” “ ” , 、svc “TcpCer”。
// : WCF , TcpCer.svc TcpCer.svc.cs, 。
public class TcpCer : ITcpCer
{
public void DoWork()
{
OperationContext.Current.GetCallbackChannel<ICallback>().TestCallBack(" ");
}
}
}
프로필
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None" />
</clientCertificate>
<serviceCertificate findValue="TestServer" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfCertificate.Validator,WcfCertificate" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBindConfig" receiveTimeout="00:20:00">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="WcfCertificate.TcpCer" behaviorConfiguration="mybehavior">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBindConfig" contract="WcfCertificate.ITcpCer"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
Web , True。
False Web 。
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
고객 센터
namespace wfTcpCer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ServiceReference1.TcpCerClient tc = new ServiceReference1.TcpCerClient(
new System.ServiceModel.InstanceContext(new CallBack()));
tc.ClientCredentials.UserName.UserName = "sa";
tc.ClientCredentials.UserName.Password = "1234";
tc.DoWorkAsync();//
}
public class CallBack : ServiceReference1.ITcpCerCallback //
{
public void TestCallBack(string hello)
{
MessageBox.Show("text callback");
}
}
}
}
프로필
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ITcpCer">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://2011-20130817ae:4503/TcpCer.svc"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ITcpCer"
contract="ServiceReference1.ITcpCer" name="NetTcpBinding_ITcpCer">
<identity>
<!-- , dns value="TestServer" certificateValidationMode="None" -->
<certificate encodedValue="AwAAAAEAAAAUAAAA3j+VKPLILWzCfoG9VXc2yhchi+kgAAAAAQAAADoCAAAwggI2MIIB5KADAgECAhDmLEMHisejr0j4qDS+rn+HMAkGBSsOAwIdBQAwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3kwHhcNMTMxMjMxMDM0MjE4WhcNMzkxMjMxMjM1OTU5WjAVMRMwEQYDVQQDEwpUZXN0U2VydmVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtXJzwFZrUgBRsLu5c8wt0iEwj/EcI9IFHK8tAraRtKsLtoWi3CHxrwi39rNaWh0SN11w8QX+0rEwAdxoxppGPPTTMbRMlcUHWHZ8oTn5V66nzYds0X2tt993KV0k1YX1ZXDuA37LZFROwksqCYfsl2sAenVkiLizzjrMVaIUPuzVvaphpxd+KcivPAYdNW/tCgC1vracULEVnu+86uPhyT9dUykIByB4rhbR0EHUNuw/4CtTsx+a3Wqn/vhPgjy08nxx+wfB/ekJmNnoz0cNVobq4WOpExDNZdGrrow9qVMcIvcGj53vGb4BhzdCwZWzf0U/K3LAJEqg+2/P+HlcPwIDAQABo0swSTBHBgNVHQEEQDA+gBAS5AktBh0dTwCNYSHcFmRjoRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mCEAY3bACqAGSKEc+41KpcNfQwCQYFKw4DAh0FAANBABjcWxmn9cVILyozv4cVvGQJ6ZfAen7pHI1MV1dZ/YhJHd1Ou6dHHafAI3755TyY7gpEHPu4xuRN6eXwYg2FkvI=" />
<!--<dns value="TestServer"/>-->
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="mye">
<clientCredentials>
<serviceCertificate>
<!-- None-->
<authentication certificateValidationMode="None"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WCF 요청 본문이 너무 길어서 400 오류 해결 방안으로 돌아갑니다.오늘 WCF로 글을 추가할 때 POST 요청 본문이 일정 문자 수량(ContentLength > 1w)을 초과하면 서버가 항상 400 오류로 되돌아오는 것을 발견했습니다. 마지막으로 WCF가 요청 본문의 길이를 제한...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.