2013-02-15 1 views
0

.net 및 WCF를 처음 사용합니다. 데이터베이스 테이블에서 데이터를 가져오고 데이터를 기반으로 SMTP 교환을 사용하여 전자 메일을 보낼 WCF 서비스 프로토 타입을 작성하려고합니다.
프로토 타입의 경우 인터페이스 및 서비스를 만들고 IIS 5.1에서 WCF 서비스를 호스팅했습니다. 테스트 콘솔의 경우이 서비스를 참조했습니다. 이제 앱을 실행할 때 콘솔에서 오류 메시지가 표시됩니다.테스트 콘솔에서 호출 할 때 WCF 서비스에서 DTO를 통해 데이터를 가져 오는 방법

<configuration> 
    <configSections> 
    <section name="Dependency" type="WW.EnterpriseLibrary.Dependency.ServiceLocatorConfigurationSection, WW.EnterpriseLibrary"/> 
    </configSections> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IEmailService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
        <security mode="TransportCredentialOnly"> 
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/> 
        <message clientCredentialType="UserName" algorithmSuite="Default"/> 
        </security> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
     <endpoint address="http://localhost/WCFEmailService/BulkEmailService.svc/EmailService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEmailService" contract="EmailService.IEmailService" name="BasicHttpBinding_IEmailService"/> 
     </client> 
    </system.serviceModel> 
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> 
    <Dependency> 
    <dependencies> 
     <add name="IEmailService" type="C:\BulkEmailPrototype\TestWcfEmailService\TestWcfEmailServiceLibrary.WW.Common.Service.Impl.EmailService, C:\BulkEmailPrototype\TestWcfEmailService\TestWcfEmailServiceLibrary.WW.Common.Service.Impl" /> 
    </dependencies> 
    </Dependency> 
</configuration> 

날 내가 뭘 잘못 알려 주시기 바랍니다 :

namespace MyWcfConsoleApp 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     // Create a proxy object and connect to the service 
     EmailServiceClient proxy = new EmailServiceClient(); 

     // Test the operations in the service 
     Console.WriteLine("Test1"); 
     //BulkEmailDTOList EmailInfo = proxy.GetBulkEmailInfo(1); 

     EmailService.IEmailService EmailInfo = ServiceLocator.Resolve<IEmailService>(); 
     BulkEmailDTOList result = new BulkEmailDTOList(); 
     result = EmailInfo.GetBulkEmailInfo(1); 

이 내가 콘솔 응용 프로그램 내의 app.config에있는 것입니다 :

코드가 모습입니다 . 내 데이터를 검색하기 위해 DTO를 호출하는 간단한 방법이 있습니까? 나는 이것에 새로운 오전 말했듯이 그렇게 힘든 시간을 보내고 .. 여기

내 구현 :

using BulkEmailDac = WW.Common.DataAccess.Impl.BulkEmailDac; 

namespace WW.Common.Service.Impl 
{ 
public class EmailService : IEmailService 
{ 

    private BulkEmailDac emailDac; 
    ErrorMsg err_msg = new ErrorMsg(); 


    public EmailService() 
    { 
     emailDac = new BulkEmailDac(); 
    } 

       public BulkEmailDTOList GetBulkEmailInfo(int recordLimit) 
     { 

      try 
      { 

       return emailDac.GetBulkEmailInfo(recordLimit); 
      } 
      catch (Exception ex) 
      { 
       if (ex is FaultException<OperationFault>) 
       { 
        throw; 
       } 
       else 
       { 

        //LOG AND THROW AN UNKNOWN EXCEPTION 
        ApplicationLog.WriteError(DateTime.Now.ToString() + "|" 
               + "GetBulkEmailInfo" + "|" 
               + ex.Message + "|" 
               + ex.StackTrace); 
        throw new FaultException<OperationFault>(new OperationFault(ex.Message, ErrorMessages.Unknown_Error_Code)); 
       } 
      } 

그리고 이것은 계약이다 : 이것은의 Web.config가

namespace WW.Common.Service.Contract 
{ 
    [ServiceContract] 
    public interface IEmailService 
    { 

    [OperationContract] 
    double Add(double n1, double n2); 

    [OperationContract] 
    double Subtract(double n1, double n2); 

    [OperationContract] 
    double Multiply(double n1, double n2); 

    [OperationContract] 
    double Divide(double n1, double n2); 

    [OperationContract] 
    [FaultContractAttribute(typeof(OperationFault))] 
    BulkEmailDTOList GetBulkEmailInfo(int recordLimit); 

    [OperationContract] 
    string Abc(string s1); 

    } 

입니다 내 서비스의 파일 :

<configuration> 
    <configSections> 
    <section name="Dependency" type="WW.EnterpriseLibrary.Dependency.ServiceLocatorConfigurationSection, WW.EnterpriseLibrary"/> 
    </configSections> 
    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelMessageLoggingListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
     <source name="System.ServiceModel" switchValue="Warning,ActivityTracing" 
     propagateActivity="true"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelTraceListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add initializeData="c:\bulkemailprototype\testwcfemailservice\wcfemailservice\web_messages.svclog" 
     type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> 
     <filter type="" /> 
     </add> 
     <add initializeData="c:\bulkemailprototype\testwcfemailservice\wcfemailservice\web_tracelog.svclog" 
     type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelTraceListener" traceOutputOptions="Timestamp"> 
     <filter type="" /> 
     </add> 
    </sharedListeners> 
    </system.diagnostics> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <connectionStrings> 
    <add name="WWDbConnect" 
     connectionString="Data Source=(labdev0320);USER ID = wwsa; Password = trex777sa;Max Pool Size=200;" 
     providerName="System.Data.OracleClient" /> 
    </connectionStrings> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBindingWithNoSecurity" maxBufferPoolSize="524288" maxReceivedMessageSize="500000"> 
      <security mode="Transport"> 
      <transport clientCredentialType="Certificate" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client/> 
    <services> 
     <service name="WW.Common.Service.Impl.EmailService" behaviorConfiguration="EmailService"> 
      <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:8270/Design_Time_Addresses/TestWcfEmailServiceLibrary/EmailService/" /> 
      </baseAddresses> 
      </host> 
      <endpoint address="EmailService" binding="basicHttpBinding" contract="WW.Common.Service.Contract.IEmailService" /> 
      <endpoint address="mex" binding="basicHttpBinding" 
        name="mexEndpoint" contract="IMetadataExchange" /> 
     </service> 
     </services> 
     <behaviors> 
     <serviceBehaviors> 
      <behavior name="EmailService"> 
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceSecurityAudit auditLogLocation="Application" 
       suppressAuditFailure="true" 
       serviceAuthorizationAuditLevel="Success" 
       messageAuthenticationAuditLevel="Success" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <diagnostics> 
     <messageLogging logEntireMessage="true" logMalformedMessages="false" 
     logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" 
     maxMessagesToLog="3000" /> 
    </diagnostics> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <Dependency> 
    <dependencies> 
     <add name="IEmailService" type="WW.Common.Service.Impl.EmailService, WW.Common.Service.Impl" /> 
    </dependencies> 
    </Dependency> 
</configuration> 

답변

0

우선, 엔드 포인트가 잘못되었습니다.

서비스의 웹 구성에서 relativeAddress의 값은 <serviceActivations>입니다. 그것은 당신이 당신의 클라이언트 응용 프로그램에서 타격해야하는 진정한 길입니다.

WCF 서비스를 테스트하는 빠르고 간단한 방법은 VISUAL_STUDIO_INSTALL_PATH \ Common7 \ IDE에있는 WCFTestClient를 사용하는 것입니다. 진정한 엔드 포인트를 알게되면이 앱에서 테스트 할 수 있습니다.

+0

serviceActivations은 어디에서 볼 수 있습니까? 내 App.config에서 볼 수 없습니다. – Ditty

+0

GetBulkEmailInfo를 호출하려고 할 때 디버깅하지 않고 디버그를 사용하여 서비스를 실행할 때 자동으로 오는 WCFTestClient 콘솔 에서조차 – Ditty

+0

도움말 ... 제발 .. – Ditty