I have a WCF service that is working with Soap. I need this working with rest as well. I have added a WebGet
attribute to my method as follows:
[OperationContract]
[WebGet(UriTemplate = "login/{username}/{password}/{PartnerID}")]
Model.PartnerAuthentication authenticate(Model.PartnerRequest request);
But when I change some configuration related to rest in config file I am getting error. not sure that my config related to rest is correct:
This is in my web.config
:
<services>
<service behaviorConfiguration="HubBehavior" name="Acquisition.AcquisitionService">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint
binding="basicHttpBinding" bindingConfiguration="basicBinding"
contract="Acquisition.IAcquisition" />
<endpoint name="wsEndpoint"
address="ws"
binding="wsHttpBinding" bindingConfiguration="wsBinding"
contract="Acquisition.IAcquisition" />
<endpoint
address="web"
behaviorConfiguration="restfulBehavior"
binding="webHttpBinding"
contract="Acquisition.IAcquisition"/>
</service>
</services>
The last endpoint in related to rest and my Behavior are:
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="HubBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
Here is a sample code segment which you can use. here i added sample method which you have to implement in your service class and then I added web config for that WCF service. Hope this will help you to solve your problem.
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/GetNameXML?name={name}")]
string GetNameXML(string name);
<system.serviceModel>
<services>
<service name="WcfService1.TestService" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="WcfService1.ITestService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
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.