クライアントがインターネット経由で展開されるクライアントサーバープロジェクトに取り組んでいます。すべてのサービスは WCF で記述され、wsHttpBinding
. クライアント コールバック機能を実装する必要があります。クライアントはファイアウォールと NAT の背後にあるため、netTcpBinding
ファイアウォール/NAT をバイパスするものを使用できると言われました。そこで、サービスとコールバック コントラクトを作成しました。
クライアント側では、これが私がそれに接続しようとしている方法です:
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
AuthorizationToken authorizationToken =
new AuthorizationToken(Session.Current.Username, Session.Current.Password, RequiredPermission.User);
using (DuplexChannelFactory<INotificationService> channel =
new DuplexChannelFactory<INotificationService>(new InstanceContext(this), binding,
new EndpointAddress("net.tcp://mywebsite.com:808/MyServices/NotificationService.svc")))
{
channel.Credentials.UserName.UserName = authorizationToken.FormatTokenForTransmission();
channel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode =
System.ServiceModel.Security.X509CertificateValidationMode.None;
INotificationService proxy = channel.CreateChannel();
proxy.Subscribe();
}
wsHttpBinding
このコードは、バインディング タイプと を除いて、サービスに接続するコードとほぼ同じですChannelFactory
。またweb.config
、次のようになります。
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpConfig" maxReceivedMessageSize="2147483647">
<security mode="Message" >
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="2147483647"/>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="netTcpConfig">
<security mode="Message" >
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="2147483647"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="MyProject.Services.NotificationService" behaviorConfiguration="authenticationBehavior">
<endpoint binding="netTcpBinding" bindingConfiguration="netTcpConfig"
contract="MyProject.ServiceContracts.INotificationService" />
<endpoint address="mex"
binding="mexTcpBinding"
bindingConfiguration=""
name="MyServiceMexTcpBidingEndpoint"
contract="IMetadataExchange" />
</service>
// other non-net.tcp services go here
</services>
<behaviors>
<serviceBehaviors>
<behavior name="authenticationBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceCredentials>
<serviceCertificate findValue="SomeCertificate" storeLocation="LocalMachine"
storeName="TrustedPeople" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyProject.Authentication.CustomAuthenticator, MyProject.Authentication" />
</serviceCredentials>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
サービス呼び出しを行うと、要求は に到達しますIIS
が、内部例外メッセージなしで例外がスローされ、サーバー側では次のトレース ログが取得されます。
The socket connection was aborted. This could be caused by an error processing
your message or a receive timeout being exceeded by the remote host, or an underlying
network resource issue. Local socket timeout was '00:01:00
これは非常に一般的なエラーであることは理解しています。私の質問は、私の Web 構成設定に何か問題がありますか? どんな助けでも大歓迎です。