Web Api 调用时出现405错误
之前可以调用成功,说明配置没问题
说明: .net core WebApi 在配置终结点时adress不需要指定svc,但是wcf服务需要
错误提示:
System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed.
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
--- End of stack trace from previous location where exception was thrown ---
at Tuhu.Service.TuhuServiceClient`1.InvokeAsync[T](Func`2 func, CancellationToken cancellationToken)
解决方案
配置终结点地址时配置完整路径,而不是只配置前缀
来源:
You have to specify full address for your service in the endpoint tag of Client configuration
address="http://localhost:8002/HelloWorldService.svc", where you put same endpoint configurations.
It did work for me while I trapped in hell...
https://stackoverflow.com/questions/18004206/protocolexception-unhandled-405-method-not-allowed-with-wcf-bindings-and-endp