您可以尝试使用 X509 证书来创建安全签名。这样,您可以握住锁和钥匙。其他 IP 将能够访问您的服务,但无法通信。您可以执行以下操作:
在服务中:
<behaviors>
<serviceBehaviors>
<behavior name="wsHttpCertificateBehavior">
<dataContractSerializer maxItemsInObjectGraph="50000"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck" />
</clientCertificate>
<serviceCertificate findValue="CN=WSE2QuickStartServer" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectDistinguishedName" />
</serviceCredentials>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
在客户端:
<behaviors>
<endpointBehaviors>
<behavior name="wsHttpCertificateBehavior">
<dataContractSerializer maxItemsInObjectGraph="50000" />
<clientCredentials>
<clientCertificate findValue="CN=WSE2QuickStartClient" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectDistinguishedName" />
<serviceCertificate>
<authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck" trustedStoreLocation="LocalMachine" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://localhost/ClientService.svc" behaviorConfiguration="wsHttpCertificateBehavior" binding="wsHttpBinding" bindingConfiguration="ApplicationServicesBinding" contract="GAINABSApplicationServices.Contracts.ServiceContracts.IClientService" name="ClientService">
<!--<identity>
<certificateReference storeName="AddressBook" storeLocation="CurrentUser"
x509FindType="FindBySubjectName" findValue="WSE2QuickStartServer"
isChainIncluded="true" />
</identity>-->
</endpoint>
</client>
您可以选择需要客户端上的身份标签来声明您在与服务通信时明确使用证书作为身份。希望这可以帮助!