WCF - (405)方法不允许。 [英] WCF - (405) Method Not Allowed.

查看:67
本文介绍了WCF - (405)方法不允许。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友!



我开始使用WCF而且我遇到了一些问题,

我通过VS2013创建新的WCF项目,当我尝试使用WcfTestClient测试WCF时,我恢复了跟随错误(405)方法不允许。

我附上了我的web.config文件,

Hello friends!

I start to work with WCF and I have some problem,
I Create new WCF project by VS2013, when I try to test the WCF with WcfTestClient I recived to follow error (405) Method Not Allowed.
I attached my web.config file ,

<system.web>
  <compilation debug="true" targetframework="4.5" />
  <httpruntime targetframework="4.5" />
</system.web>
<system.servicemodel>
  <services>
    <service name="ConnectingServer.ServerConnectionAPI">
      <endpoint address="http://localhost:2607/ServiceConnection">
        binding="wsHttpBinding"  name="ServiceEndPoint"
        contract="ConnectingServer.IServerConnectionAPI" />
    </endpoint></service>
  </services>
  <behaviors>
    <servicebehaviors>
      <behavior>
        <servicemetadata httpgetenabled="true" httpsgetenabled="true" />
        <servicedebug includeexceptiondetailinfaults="true" />
      </behavior>
    </servicebehaviors>
  </behaviors>
  <protocolmapping>
      <add binding="wsHttpBinding" scheme="https" />
  </protocolmapping>
  <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="false" />
</system.servicemodel>
<system.webserver>
  <modules runallmanagedmodulesforallrequests="true" />
  <directorybrowse enabled="true" />
</system.webserver>



异常完整曲目:


The exception full track :

Server stack trace: 
   at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
   at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
   at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IServerConnectionAPI.IsUserRegister(String userName)
   at ServerConnectionAPIClient.IsUserRegister(String userName)

Inner Exception:
The remote server returned an error: (405) Method Not Allowed.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)



谢谢。

MAK


Thanks.
MAK

推荐答案

请发布完整的web.config文件,默认情况下基本WCF会工作,除非有些设置被覆盖了。由于405存在,合同存在但访问方式不存在(例如,在GET方法上尝试POST,跨域,违反了服务安全性)

您是否更改了任何VS的默认WCF模板?



由于您使用的是wsHttpBinding,因此某些安全设置设置不正确。



1 )首先将绑定更改为basicHttpBinding,然后查看是否可以获取WSDL。如果是,则逐步更改设置

2)检查服务和客户端配置和代码的寻址模式(获取,发布等)

3)参见如果WebGet出现在服务合同或WebInvoke的Method属性上

4)检查模拟模式



如果没有任何作用,那么发布yr整个serviceConfig
Please post your complete web.config file, by default the basic WCF will work unless some settings are overridden. As 405 is there, the contract exists but the way of access is not (eg trying POST on a GET method, cross domain, service security violated)
Have you changed any of the VS's default WCF templates?

Since you are using wsHttpBinding, there's been some security settings which are not set properly.

1) Change the binding to basicHttpBinding first and then see if you can get the WSDL. If yes then change the settings step-by-step
2) Check the addressing mode (get, post etc) on the service & client configs & code
3) See if WebGet is present on the service contracts or the WebInvoke's Method attribute
4) Check the impersonation modes

If nothing works, then post yr entire serviceConfig


你好,

对于迟到的回复很抱歉。

我切换到basicHttpBinding并且我恢复了相同的行为。 />
我附上了我的web.config [服务器配置]文件



Hello ,
Sorry for the late respond.
I switch to basicHttpBinding and I recived the same behavior.
I attached my web.config [Server config] file

<!--?xml version="1.0"?-->
<configuration>

  <appsettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true">
  </add></appsettings>
  <system.web>
    <compilation debug="true" targetframework="4.5">
    <httpruntime targetframework="4.5">
    
  </httpruntime></compilation></system.web>
  
  <system.servicemodel>
  
    <services>
      <service name="MyConnectingServer.ServerConnectionAPI">
        <endpoint address="http://localhost:2607/MyServiceConnection" binding="basicHttpBinding" bindingconfiguration="" name="basicHttpBinding" contract="MyConnectingServer.IServerConnectionAPI">
      </endpoint></service>
    </services>
    <bindings>
      </bindings>
    <behaviors>
      <servicebehaviors>
        <behavior>       
          <servicemetadata httpgetenabled="true" httpsgetenabled="true">
          <servicedebug includeexceptiondetailinfaults="true">
        </servicedebug></servicemetadata></behavior>
      </servicebehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="wsHttpBinding" scheme="https">
    </protocolMapping>    
    <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="false">
  </servicehostingenvironment></add></system.servicemodel>
  <system.webserver>
    <modules runallmanagedmodulesforallrequests="true">
    <directorybrowse enabled="true">
  </directorybrowse></modules></system.webserver>
</configuration>







为了测试服务,我使用WcfTestClient(微软测试工具)。

配置文件是:




For testing the service I use the WcfTestClient (microsoft test tool).
The config file is:

<configuration>
    <system.servicemodel>
        <bindings>
            <basichttpbinding>
                <binding name="basicHttpBinding" sendtimeout="00:05:00">
            </binding></basichttpbinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:2607/MyServiceConnection" binding="basicHttpBinding" bindingconfiguration="basicHttpBinding" contract="IServerConnectionAPI" name="basicHttpBinding">
        </endpoint></client>
    </system.servicemodel>
</configuration>



==================================

合同文件中函数decleration的示例:



[ServiceContract]

公共接口IServerConnectionAPI

{

[OperationContract]

布尔值IsUserRegister(字符串userName);

}



感谢您的帮助。

MAK


==================================
Example of function decleration in the contract file :

[ServiceContract]
public interface IServerConnectionAPI
{
[OperationContract]
Boolean IsUserRegister(string userName);
}

Thanks for your help.
MAK


服务合同和客户合同不同< br $>
服务器:MyConnectingServer.IServerConnectionAPI

客户端:IServerConnectionAPI(这也需要命名空间)



你能做到吗?浏览服务的WSDL。尝试浏览http:// localhost:2607 / MyServiceConnection.svc?wsdl
The contracts in service and client are different
server: MyConnectingServer.IServerConnectionAPI
client: IServerConnectionAPI (this needs the namespace as well)

are you able to browse the WSDL for the service. Try to browse the http://localhost:2607/MyServiceConnection.svc?wsdl


这篇关于WCF - (405)方法不允许。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆