简体   繁体   中英

WCF 4 Service with REST/SOAP endpoints in IIS 7.5

Hello and thank you for reading.

I'm trying to get a service hosted in IIS 7.5, that has multiple endpoints exposed.

I have a feeling the problem lies within my web.config, but I'll post my service code in here. There's no interface file, as I'm using the newer features of WCF 4, there's also no .svc file.

All the routing, from my understanding is handled in Global.asax.cs using the RouteTable feature.

Regardless, onto the code / config -

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class Service1
{
    // TODO: Implement the collection resource that will contain the SampleItem instances

    [WebGet(UriTemplate = "HelloWorld")]
    public string HelloWorld()
    {
        // TODO: Replace the current implementation to return a collection of SampleItem instances
        return "Hello World!";
    }
}

And now, the config with the changes I thought would need to be made (I'm not sure if I needed to keep the standardEndpoints block, but with or without it I'm still getting error messages. -

<services>
  <service name="AiSynthDocSvc.Service1" behaviorConfiguration="HttpGetMetadata">
    <endpoint name="rest"
              address=""
              binding="webHttpBinding"
              contract="AiSynthDocSvc.Service1"
              behaviorConfiguration="REST" />
    <endpoint name="soap"
              address="soap"
              binding="basicHttpBinding"
              contract="AiSynthDocSvc.Service1" />
    <endpoint name="mex"
              address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>
</services>    

<behaviors>
  <endpointBehaviors>
    <behavior name="REST">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="HttpGetMetadata">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<standardEndpoints>
  <webHttpEndpoint>
    <!-- 
        Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
        via the attributes on the <standardEndpoint> element below
    -->
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
  </webHttpEndpoint>
</standardEndpoints>

The Global.asax.cs file was left alone.

Again I'm pretty sure it has something to do with my config. The error I'm getting when I try to access any of the endpoints defined is -

The endpoint at '' does not have a Binding with the None MessageVersion. 'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings.

Anyone have any ideas on this one?

Thanks,

Zachary Carter

OK, I tried to replicate your stuff - works like a charm for me :-)

  • I used your service class - no changes
  • I used your RegisterRoutes call in global.asax.cs

When I launch the web app from within Visual Studio, I get Cassini (the built-in web server) come up on http://localhost:3131/ - this might wary in your case.

Now, I can easily navigate there with a second browser window, and I do get a simple response on this URL:

http://localhost:3131/Service1/HelloWorld
+--------------------+ 
 from Cassini
                     +--------+
                   name (first param) in ServiceRoute registration
                              +-----------+
                               from your URI template on the WebGet attribute

Does the same URL work for you??

Update: here's my config - I can connect to http://localhost:3131/Service1/HelloWorld in the browser using REST, and I can connect to http://localhost:3131/Service1/soap with the WCF Test Client to make a SOAP call (my Service1 lives in the RestWebApp namespace - thus my service and contract names are a tad different than yours - but other than that, I believe it's identical to your own config):

  <system.serviceModel>
    <serviceHostingEnvironment     
        aspNetCompatibilityEnabled="true" />
    <services>
      <service name="RestWebApp.Service1" behaviorConfiguration="Meta">
        <endpoint name="rest" 
                  address=""
                  binding="webHttpBinding"
                  contract="RestWebApp.Service1"
                  behaviorConfiguration="REST" />
        <endpoint name="SOAP"
            address="soap"
            binding="basicHttpBinding"
            contract="RestWebApp.Service1" />
        <endpoint name="mex"
            address="mex"
            binding="mexHttpBinding"
            contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="REST">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Meta">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
        Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
        via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

Thanks for this it helped me a lot.

The issue in my case was that I had a default behaviour configured that contains webHttp. After giving it the name="REST" and setting my webHttpBinding endpoint behaviourConfiguration ="REST" I had no further errors.

<system.serviceModel>
<bindings>
  <customBinding>
    <binding name="CustomBinding_IMobileService">
      <binaryMessageEncoding />
      <httpTransport />
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address="http://localhost:6862/silverlight/services/MobileService.svc"
    binding="customBinding" bindingConfiguration="CustomBinding_IMobileService"
    contract="AlchemyMobileService.IMobileService" name="CustomBinding_IMobileService" />
</client>
<services>
  <service name="MobileService.Alchemy">
    <endpoint address="http://localhost:8732/mobileservice" binding="webHttpBinding" contract="MobileService.IAlchemy" behaviorConfiguration="REST">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="REST">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM