【发布时间】:2019-02-05 21:25:58
【问题描述】:
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>
【问题讨论】:
-
你能发布一个 wcf 调用的例子吗?您是否在项目中添加了该服务作为参考?
-
是的,我做到了。我创建了服务客户端的实例,然后调用了该方法。我得到了 405。我很快就会发布一个通话示例。
-
这可能只是您在客户配置中的错字吗?
endpoint的address末尾有一个 空格 - 尝试删除那个 .... -
不,我删除了空间,它仍然返回 405