I am new to WCF so please bear with me.
Using the latest version of the WCF REST Starter kit, I created a web service that is being called by an Android application. The RESTful endpoint is working fine but I would like to create a SOAP endpoint so that a .NET client will be able to use it and generate all the necessary classes.
I am still using the default configuration file and I am a little confused about what I need to do to it.
Here it is
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<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>
</configuration>
I think I need to add the following somewhere into the config file but I am unsure where it belongs or if I am on the right path.
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="Service1"/>
<endpoint name="soap" address="soap" binding="basicHttpBinding" contract="Service1"/>开发者_StackOverflow;
I only have one class and that is Service1.cs. I have tried to make some changes but I have had no success.
I would like to know what I have to add and an explanation of why it's needed would be wonderful.
-- Update --
After I inserted the services tag, I was having trouble getting the 'Add Service Reference' feature to work in visual studio. I found out that 'HttpGetEnabled' needs to be true, so it would publish the service metadata to http.
I added this and it seems like its working.
<behaviors>
<serviceBehaviors>
<behavior name="Service1Behavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
</behavior>
</serviceBehaviors>
</behaviors>
If I add more services, do I have to create two more endpoints for that service too?
Thanks.
If you want to expose additional endpoints on your service, you need to add those to the <service name="....">
tag in your config:
<system.serviceModel>
<services>
<service name="NameSpace.ServiceClassName>
<endpoint name="rest"
address=""
binding="webHttpBinding"
contract="IService1" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
contract="IService1" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
You're obviously using the WCF 4 standard endpoints being exposed - if you want to change that, you will need to explicitly spell out all your config you need.
Now, your service (as implemented in ServiceClassName
in the NameSpace
namespace) will have three endpoints:
- the base address of your *.svc file will be the REST endpoint using
webHttpBinding
- the
(service.svc)/soap
address will be the same contract (same service methods), but using the SOAP-basedbasicHttpBinding
- the
(service.svc)/mex
address will have the service metadata for the SOAP clients
精彩评论