2012-01-24 6 views
7

मैं कुछ इस तरह है:एक वेबसाइट मुद्दे में एक WCF सेवा होस्टिंग: System.ArgumentException: ServiceHost केवल श्रेणी सेवा प्रकार का समर्थन करता

MathServiceLibrary (WCF सेवा पुस्तकालय)

[ServiceContract] 
public interface IMathService 
{ 
     [OperationContract] 
     int Add(int x, int y); 
     [OperationContract] 
     int Multiply(int x, int y); 
} 

public class MathService : IMathService 
{ 
     public int Add(int x, int y) 
     { 
      return x + y; 
     } 

     public int Multiply(int x, int y) 
     { 
      return x * y; 
     } 
} 

<behaviors> 
    <serviceBehaviors> 
     <behavior name="defaultServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service behaviorConfiguration="defaultServiceBehavior" 
      name="MathServiceLibrary.MathService"> 
     <endpoint 
      address="mex" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" /> 
     <endpoint 
      address="math" 
      binding="wsHttpBinding" 
      contract="MathServiceLibrary.IMathService" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8080/" /> 
      </baseAddresses> 
     </host> 
    </service> 
</services> 

अगर मैं चलाने यह मैं डब्ल्यूसीएफ टेस्ट क्लाइंट देख सकता हूं और सबकुछ ठीक है।

अब मैं इस सेवा को आईआईएस में होस्ट करना चाहता हूं इसलिए मैं एक वेबसाइट बनाता हूं और MathServiceLibrary का संदर्भ जोड़ता हूं।

मैं इस ms.svc

<%@ ServiceHost Language="C#" Debug="true" 
    Service="MathServiceLibrary.IMathService" %> 

और इस web.config

<system.serviceModel> 
     <services> 
      <service behaviorConfiguration="defaultServiceBehavior" name="MathServiceLibrary.MathService"> 
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
       <endpoint address="" binding="wsHttpBinding" contract="MathServiceLibrary.IMathService"> 
        <identity> 
         <dns value="localhost"/> 
        </identity> 
       </endpoint> 
      </service> 
     </services> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="defaultServiceBehavior"> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="false"/> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

है जब मैं सही ms.svc दृश्य पर क्लिक करें ब्राउज़र में मैं इस मिल:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: ServiceHost only supports class service types.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: ServiceHost only supports class service types.]
System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) +12229075
System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +55
System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +154
System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +49
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +151
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +30
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +420
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1440
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/MathWebSite/ms.svc' cannot be activated due to an exception during compilation. The exception message is: ServiceHost only supports class service types..]
System.Runtime.AsyncResult.End(IAsyncResult result) +679246
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +355
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

मैं समझ नहीं सकता मैं क्या खो रहा हूँ बाहर।

उत्तर

13

रूप

नीचे
<%@ ServiceHost Language="C#" Debug="true" Service="MathServiceLibrary.MathService" % > 

आप इंटरफ़ेस नाम

+0

धन्यवाद, यह काम करता है। – gigi

3

आपका .svc फ़ाइल गलत है के बजाय वर्ग के नाम देना है अपने ms.svc बदलें। यह कार्यान्वयन नहीं, इंटरफ़ेस का संदर्भ देता है। इसे इस पर बदलें: <%@ ServiceHost Language="C#" Debug="true" Service="MathServiceLibrary.MathService" %>

+0

धन्यवाद, यह काम करता है। – gigi

+0

मेरे पास एक अन्य प्रोजेक्ट पर मेरा कार्यान्वयन था, न कि एक ही नामस्थान में, क्या कोई समस्या है? – kbvishnu

3

एसवीसी फ़ाइल को इंटरफ़ेस नाम के बजाय कक्षा का नाम होना चाहिए। एक नमूना एसवीसी फ़ाइल नीचे सामग्रियां हैं:

<%@ ServiceHost Language="C#" Debug="true" Service="SampleService.Service1" CodeBehind="Service1.svc.cs" %> 

आशा है कि मदद करता है।

3

अपने एसवीसी फ़ाइल में प्रविष्टि गलत है:

बजाय

:

<%@ ServiceHost Language="C#" Debug="true" 
    Service="MathServiceLibrary.IMathService" %> 

आप की आवश्यकता है:

<%@ ServiceHost Language="C#" Debug="true" 
    Service="MathServiceLibrary.MathService" %> 

आप में सेवा कार्यान्वयन वर्ग परिभाषित करने की जरूरत Service= विशेषता - सेवा अनुबंध!

संबंधित मुद्दे