WCF 4 Service with REST / SOAP Endpoints in IIS 7.5

Hi, thank you for reading.

I am trying to get a service hosted in IIS 7.5 that has several endpoints.

I have a feeling that the problem lies in my web.config, but I have posted my service code here. There is no interface file since I am using the new WCF 4 features, there is also no .svc file there.

All routing, from my understanding, is processed in Global.asax.cs using the RouteTable function.

Regardless of the code in / 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 configuration with the changes that I thought would need to be made (I'm not sure that I need to save the standardEndpoints block, but with or without it, I still get 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 is left alone.

Again I'm sure this has something to do with my configuration. The error I get when I try to access any of the specified endpoints is

Endpoint in '' has no binding with None MessageVersion. "System.ServiceModel.Description.WebHttpBehavior" is for use only with WebHttpBinding or similar bindings.

Anyone have any ideas on this?

Thanks,

Zachary Carter

+4
source share
2 answers

Ok, I tried to reproduce your stuff - it works like a charm for me :-)

  • I used your class of service - no change
  • I used your call to RegisterRoutes in global.asax.cs

When I launch a web application from Visual Studio, I get Cassini (embedded web server) at http://localhost:3131/ - this may be a warning in your case.

Now I can easily navigate there with the second browser window, and I get a simple answer at 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 use for you?

Update: here is my configuration - I can connect to http://localhost:3131/Service1/HelloWorld in the browser using REST, and I can connect to http://localhost:3131/Service1/soap using the WCF test client to call SOAP (my Service1 lives in the RestWebApp namespace, so my service and contract names are slightly different from yours, but apart from that, I believe that it is identical to your own configuration):

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

Thanks for that, it helped me a lot.

In my case, the problem was that I had a default behavior configured that contained webHttp. After providing name = "REST" and setting my endpoint webHttpBindingConfiguration = "REST", I had no additional 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> 

0
source

Source: https://habr.com/ru/post/1347941/


All Articles