views:

411

answers:

2

Howdy,

I have a pretty big webapp that's being built in MVC. I'm also abstracting common code into a framework which sits in a separate project. Hopefully this framework will be used in other projects in the near future. There are a few Silverlight apps that are a part of this framework, and one of their jobs is to upload files a chunk at a time. In order to achieve this, I want them to communicate with a WCF service, which also lives in the framework project. I am having problems with this.

I copied the app.config data VS2008 added to my framework project for the service into the web.config, but that didn't seem to work.

After a bit of searching I discovered that you can write a service with a code behind, by creating a .svc file and a matching .cs file, so I tried creating MyService.svc like this:

<% @ServiceHost language="C#"
Service="MyFramework.MyService"
%>

As my service exists within another project, there's no code behind file to reference, so I assumed the Namespace.Class reference would be enough in there.

I also added MyService.svc/{*pathInfo} to the Ignored Routes in my Global.asax file.

However when I try to browse to localhost:x/MyService.svc, or when I try to find the service using the Add Service tool in VS2008, it just seems to hang.

What am I doing wrong?

Anthony

+2  A: 

Yes well your WCF service is SOAP based - you won't be able to just browse to it and see anything.

If you want to see the service description and all, you'll need to enable the "metadata" exchange by

  • specifying the <serviceMetadata> behavior in your service config
  • defining a "mex" (metadata exchange) endpoint in your service config

To enable the serviceMetadata, you need this section in your service config (web.config - section <system.serviceModel>):

<system.serviceModel>
   <behaviors>
   <serviceBehaviors>
       <behavior name="MEXServiceBehavior">
               <serviceMetadata httpGetEnabled="True"/>
           </behavior>
       </serviceBehaviors>
   </behaviors>

and you'll need to reference that from your service:

<system.serviceModel>
    <service name="....." behaviorConfiguration="MEXServiceBehavior" ....>

To define a MEX endpoint, use something like this:

<services>
    <service name="....." behaviorConfiguration="MEXServiceBehavior" ....>
        <endpoint address="http://localhost:5555/YourSerice/mex"
                  binding="mexHttpBinding" contract="IMetadataExchange" />

There should be plenty of documentation available to show you how to do this (including plenty of questions asked and answered here on Stackoverflow on that topic).

Just a tiny nitpick: you're not really hosting your service "in ASP.NET MVC" - you're hosting it in IIS - the MS web server product. It is totally independent of whether you're using ASP.NET MVC, ASP.NET webforms, or anything else, for that matter.

Marc

marc_s
A: 

What about you web.config? have you added this sort of thing

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyFramework.MyServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling 
          maxConcurrentCalls="200"
          maxConcurrentSessions="100"
          maxConcurrentInstances="100" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service 
      behaviorConfiguration="MyFramework.MyServiceBehavior"
      name="MyFramework.MyService">
    <endpoint binding="wsHttpBinding"              
              bindingConfiguration="MyServiceBindingSettings" 
              contract="MyFramework.IMyService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="MyServiceBindingSettings" 
             closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" 
             maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"
             messageEncoding="Text" textEncoding="utf-8">
      <readerQuotas 
          maxDepth="2147483647" 
          maxStringContentLength="2147483647" 
          maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
          maxNameTableCharCount="2147483647"/>
    </binding>
  </wsHttpBinding>
</bindings>

Anthony Johnston