2013-03-01 24 views
9

WCF Barındırma Hizmetleri:Ben 3 proje ile bir çözüm var Asp.Net MVC Projesi

  1. ConsoleClient (WCF için)
  2. ServiceLibrary
  3. Web (asp.net mvc (test WCF hizmeti için) proje)

Ben app.config benim ServiceLibrary projesinde bazı ayarları yapmış

<system.serviceModel> 
    <services> 
     <service name="MrDAStoreJobs.ServiceLibrary.AdvertisementService"> 
     <clear /> 
     <endpoint address="http://localhost:8050/ServiceLibrary/basic" binding="basicHttpBinding" bindingConfiguration="" contract="MrDAStoreJobs.ServiceLibrary.Interface.IAdvertisementService" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8050/Design_Time_Addresses/MrDAStoreJobs/ServiceLibrary/AdvertisementService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, 
      set the value below to false before deployment --> 
      <serviceMetadata httpGetEnabled="True" /> 
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true. Set to false before deployment 
      to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 

Bu projeyi çalıştırdığımda, her şey normalde wcf test istemcisi kullanıyor.

Ayrıca, wcf hizmetimi barındırmak üzere Web project(mvc) numaralı telefonuma WcfDataServiceTest.svc ekledim.

Yani, sorularım şunlardır:

  1. Aslında bu wcf hizmeti barındırmak için benim web projesi (web.config) için gereken ne yapılandırma?
  2. Ve sonra test etmek için konsol uygulamasını çalıştırmak istiyorum?

Not: i konsol projesi kullanarak hizmet test ettik ama bu WCF testi müşteriden vekil nesil başlamıştı. Bu arada

, wcfDataServiceTest.svc dosyası şuna benzer: Benim MVC projesinde doğrudan WCF barındırma hizmeti ediyorum

public class WcfDataServiceTest : DataService<AdvertisementService> 
{ 
    // This method is called only once to initialize service-wide policies. 
    public static void InitializeService(DataServiceConfiguration config) 
    { 
     // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. 
     // Examples: 
     config.SetEntitySetAccessRule("Advertisements", EntitySetRights.AllRead); 
     // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All); 
     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; 
    } 
} 

cevap

14

.

Web.config servis yapılandırma: Burada

<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name=""> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<bindings> 
    <customBinding> 
    <binding name="customBinding0"> 
     <binaryMessageEncoding /> 
     <httpTransport /> 
    </binding> 
    </customBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
<standardEndpoints> 
    <webHttpEndpoint> 
    <standardEndpoint name="" helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="1048576"> 
     <readerQuotas maxStringContentLength="1048576" /> 
    </standardEndpoint> 
    </webHttpEndpoint> 
</standardEndpoints> 
</system.serviceModel> 

hizmet sınıfı bulunuyor: Aşağıda Yapılandırılma şekli genel bir örnektir

[ServiceContract] 
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class MyService 
{ 
    [OperationContract] 
    [WebInvoke(UriTemplate = "{personId}", Method = "GET")] 
    public Person Get(string personId) 
    { 
     return new Person(); 
    } 
} 

Ve burada benim MVC ortamında kayıt gidiyordum Global.asax

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    RouteTable.Routes.Add(new ServiceRoute("SVC/My", new WebServiceHostFactory(), typeof(MyService))); 
} 
+0

Ben ServiceRoute bulamıyorum. İsim alanını bilen var mı? – Rap

+0

Rap, ServiceRoute için ad alanı (ve dll) System.ServiceModel.Activation olduğunu. Ayrıca WebServiceHostFactory için System.ServiceModel.Web dll'ye de ihtiyacınız olacak. –

1

Here nasıl yapılır açıklaması ile ilgili bir blog yazısıdır. ASP.NET MVC 4 uygulamasında dd WCF servisi.

Sen eklemek gerekir:

<endpointBehaviors> 
    <behavior name="restBehavior"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors>