WCF service is hosted in a Windows service. I get successful response from web browser, but I can't call it form a Winforms application. I always get an error #405. Any ideas?
I have enabled "CORS" in my WCF service, I turned on all the required components from "Windows feature on and off ".
This is my client's app.config
file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
<endToEndTracing propagateActivity="true" activityTracing="true"
messageFlowTracing="true" />
</diagnostics>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint
address="http://localhost:8080/ "
behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding"
contract="IScaleService" />
</client>
</system.serviceModel>
</configuration>
This is my WCF service config file:
<configuration>
<appSettings>
<add key="port" value="COM3"/>
</appSettings>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WindowsScaleTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8080/mex"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<services>
<service name="ScaleService.Scale"
behaviorConfiguration="WindowsScaleTypeBehaviors">
<endpoint
address=""
behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP"
contract="ScaleService.IScaleService" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Finally, I found what's wrong with my app. The auto generated proxy class did not add webget attribute to the operation.
[System.ServiceModel.Web.WebGet] [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IScaleService/Get_Available_Ports", ReplyAction="http://tempuri.org/IScaleService/Get_Available_PortsResponse")] ScaleService.Lib.Ports[] Get_Available_Ports();