2013-03-01 13 views
9

मैं 3 परियोजनाओं के साथ एक समाधान है:Asp.Net MVC में WCF सेवा होस्टिंग परियोजना

  1. ConsoleClient
  2. ServiceLibrary (WCF के लिए)
  3. वेब (asp.net MVC के (परीक्षण WCF सेवा के लिए) परियोजना)

मैं app.config में मेरे ServiceLibrary परियोजना में कुछ सेटिंग्स किया है

<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> 

जब मैं इस प्रोजेक्ट को चलाता हूं, तो हर चीज आमतौर पर डब्ल्यूसीएफ परीक्षण क्लाइंट का उपयोग करती है।

अब, मैंने अपने डब्ल्यूसीएफ सेवा की मेजबानी के लिए अपने Web project(mvc) में WcfDataServiceTest.svc भी जोड़ा है।

तो, मेरे सवाल कर रहे हैं:

  1. क्या विन्यास मैं अपने वेब परियोजना (web.config) वास्तव में इस WCF सेवा की मेजबानी करने के लिए की जरूरत है?
  2. और फिर मैं इसे परीक्षण करने के लिए कंसोल ऐप चलाने के लिए चाहता हूं?

नोट: मैं अपने सेवा कंसोल प्रोजेक्ट का उपयोग कर परीक्षण किया है लेकिन यह है कि WCF परीक्षण ग्राहक से प्रॉक्सी पीढ़ी हो रही थी।

वैसे, wcfDataServiceTest.svc फ़ाइल इस तरह दिखता है:

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; 
    } 
} 

उत्तर

14

मैं एक WCF सेवा सीधे होस्टिंग कर रहा हूँ मेरी MVC परियोजना में।

Web.config सेवा विन्यास:

<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> 

यहाँ है सेवा वर्ग:

[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(); 
    } 
} 

यहाँ और जहां मैं अपने MVC में पंजीकृत हूँ नीचे यह कैसे संरचित है की एक सामान्य उदाहरण है ग्लोबल.एएसएक्स

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

मैं ServiceRoute नहीं मिल रहा। किसी को नामस्थान पता है? – Rap

+0

रैप, ServiceRoute के लिए नेमस्पेस (और डीएलएल) System.ServiceModel.Activation है। आपको WebServiceHostFactory के लिए System.ServiceModel.Web dll की भी आवश्यकता होगी। –

1

Here एक ब्लॉग पोस्ट है जिसमें वर्णन किया गया है कि कैसे एएसपी.नेट एमवीसी 4 आवेदन में डीडी डब्ल्यूसीएफ सेवा।

आप जोड़ना चाहिए:

<endpointBehaviors> 
    <behavior name="restBehavior"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
संबंधित मुद्दे