0
저는 WCF를 처음 사용하고 테스트 웹 사이트와 서비스를 설치했습니다. 제대로 IsOneWay WCF 서비스를 호출하고 클라이언트를 올바르게 호출하는 방법
나는 웹 서비스를 생성하고 그것에게 isoneway 속성을 준 사용자에게
- 전화 서비스 : 나는이 두 가지를 달성하려고 해요. 나는 사용자를 차단하지 않고 그것을 호출 할 수 있었지만 나는 클라이언트를 닫지 않을까 걱정된다. 어떻게하면 사용자를 차단하지 않고이 서비스를 호출 할 수 있습니까? 비동기 메서드 (TestServiceAsync)를 사용해야합니까? BeginXX, EndXX 메서드를 사용해야합니까?
클라이언트 :
Dim callservice As New WCFEmailServices.EmailServiceClient() callservice.TestService() callservice.Close()
Webservice를 :
<ServiceContract()> _ Public Interface IEmailService <OperationContract(IsOneWay:=True)> _ Sub TestService() End Interface Public Class EmailService Implements IEmailService Public Sub TestService() Implements IEmailService.TestService Dim srvBody As String = "" srvBody = "START: " + DateTime.Now.ToLongTimeString() + System.Environment.NewLine Thread.Sleep(10000) srvBody += "END: " + DateTime.Now.ToLongTimeString() + System.Environment.NewLine Me.SendEmail("[email protected]", "test", srvBody, Nothing) End Sub Function SendEmail(ByVal srpTo As String, ByVal srpSubject As String, ByVal srpBody As String, ByVal srpAttachmentPath As String) As Boolean Dim MailMsg As New MailMessage(New MailAddress("[email protected]"), New MailAddress(srpTo)) MailMsg.BodyEncoding = Encoding.UTF8 MailMsg.Subject = srpSubject MailMsg.Body = srpBody MailMsg.IsBodyHtml = True If srpAttachmentPath IsNot Nothing Then Dim srvAttachment As New Attachment(srpAttachmentPath) MailMsg.Attachments.Add(srvAttachment) End If Dim SmtpMail As New SmtpClient("smtp.gmail.com", 587) SmtpMail.UseDefaultCredentials = False SmtpMail.EnableSsl = True SmtpMail.Credentials = New System.Net.NetworkCredential("[email protected]", "password") Try SmtpMail.Send(MailMsg) Catch Return False End Try Return True End Function End Class
WebConfig :
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IEmailService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Message"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" /> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://localhost:61450/EmailService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEmailService" contract="WCFEmailServices.IEmailService" name="WSHttpBinding_IEmailService"> <identity> <servicePrincipalName value="host/localhost" /> </identity> </endpoint> </client> <services> <service behaviorConfiguration="WCFService.Service1Behavior" name="WCFService.Service1"> <endpoint address="" binding="wsHttpBinding" contract="WCFService.IService1"> <identity> <servicePrincipalName value="host/localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> <service behaviorConfiguration="ClientWebApp.EmailServiceBehavior" name="ClientWebApp.EmailService"> <endpoint address="" binding="wsHttpBinding" contract="ClientWebApp.IEmailService"> <identity> <servicePrincipalName value="host/localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="WCFService.Service1Behavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> <behavior name="ClientWebApp.EmailServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
나는 WCF에 손실 조금 있어요. 비 차단 클라이언트를 적절하게 종료하려면 무엇을 권하고 싶습니까? – mga911
MSDN에 따르면 클라이언트가 비 차단 호출을 요구하는 경우 AsyncPattern 연산을 구현해야합니다. http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.asyncpattern.aspx – dhirschl