Click here to Skip to main content
15,886,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ,
HTML
<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)

Thanks.
MAK
Posted
Updated 27-May-15 1:33am
v2
Comments
Peter Leow 8-Apr-15 5:54am    
Check this out: http://stackoverflow.com/questions/13228995/wcf-error-405-method-not-allowed
[no name] 8-Apr-15 6:27am    
It's still not working to me.
May you have any sample code that working with WcfTestClient sw .
10x.

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
 
Share this answer
 
Hello ,
Sorry for the late respond.
I switch to basicHttpBinding and I recived the same behavior.
I attached my web.config [Server config] file

HTML
<!--?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>



For testing the service I use the WcfTestClient (microsoft test tool).
The config file is:
HTML
<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>

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

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

Thanks for your help.
MAK
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900