【发布时间】:2013-07-10 04:29:34
【问题描述】:
我目前正在使用一个使用 RESTful 服务的应用程序。还有另一个运行自托管 WCF 服务的应用程序。我想从 restful 服务中使用自托管服务,但我遇到了问题。我得到一个 (405) Method Not Allowed。
这是自托管服务的创建和托管方式
ServiceHost host = new ServiceHost(typeof(LiveService));
host.Open();
这是我尝试在 restful 服务中使用该功能的方式
BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement();
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };
CustomBinding ServiceCustomBinding = new CustomBinding(binaryMessageEncoding, httpTransport);
EndpointAddress ServiceEndpointAddress = new EndpointAddress(string.Format("http://{0}/LiveService", host));
LiveWebServiceClient client = new LiveWebServiceClient(ServiceCustomBinding, ServiceEndpointAddress);
这是一个服务示例
[ServiceContract]
public interface ILiveService
{
[OperationContract]
string Hello();
}
public string Hello()
{
return "Hello";
}
我做了一些研究,我猜是因为我是从一个安静的服务中调用的。我曾尝试使用 [WebGet()] 和 [WebInvoke(Method="GET")] 但似乎没有什么不同。不知道我错过了什么。
【问题讨论】:
-
您在 string.Format("http://{0}/LiveService", host) 中设置的主机值是多少?
-
我传入了值。这最终成为问题,我没有包括自托管服务的端口。
标签: wcf web-services rest