繁体   English   中英

Windows服务中托管的消耗Winform的WCF服务出现错误#405(不允许使用方法e)

[英]Winform consuming WCF service hosted in a Windows service got error #405 (method not allowed 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM