使用 Windows 服务中托管的 WCF 服务的 Winform 收到错误 #405(方法不允许 e)



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>

最后,我发现了我的应用程序的问题。 自动生成的代理类未将 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((;

最新更新