WCF服务托管在Windows服务中。我从Web浏览器获得了成功的响应,但是无法将其称为Winforms应用程序。我总是收到错误#405。有什么想法吗?
我在WCF服务中启用了“ CORS”,我从“打开和关闭Windows功能”中打开了所有必需的组件。
这是我客户的app.config
文件
<?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>
这是我的WCF服务配置文件:
<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>
答案 0 :(得分:1)
最后,我发现我的应用程序出了什么问题。 自动生成的代理类未将webget属性添加到操作中。
[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();