我正在尝试联系托管在控制台应用程序中的基本REST服务(由于特定于我们的产品的原因,我们不能托管在IIS中)。我可以访问localhost:8002/Session_REST/,wsdl显示得很好。但是如果我尝试localhost:8002/Session_REST/HelloWorld_GET或localhost:8002/Session_REST/HelloWorld_ get / -我得到的只是一个405错误:找不到方法。
应用程序配置:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Proprietary.WebServices.Session_REST" behaviorConfiguration="servBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8002/Session_REST/"/>
</baseAddresses>
</host>
<endpoint address="xmlService" binding="webHttpBinding" behaviorConfiguration="restBehavior" contract="Proprietary.WebServices.ISession_REST">
<identity>
<userPrincipalName value="warren_thompson@proprietary.com" />
</identity>
</endpoint>
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>控制台应用程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
using System.ServiceModel;
using Proprietary.WebServices;
using Proprietary.Framework;
namespace MyTestConsole
{
class Program
{
static void Main(string[] args)
{
ServiceHost testServiceHost2 = null;
try
{
testServiceHost2 = new ServiceHost(typeof(Session_REST));
testServiceHost2.Open();
Console.WriteLine("Server Started");
Console.ReadLine();
}
finally
{
if (testServiceHost2 != null)
{
((IDisposable)testServiceHost2).Dispose();
}
}
}
}
}WCF合同:使用系统;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Proprietary.Framework;
using System.IO;
namespace Proprietary.WebServices
{
[ServiceContract]
public interface ISession_REST
{
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
string HelloWorld_POST();
[OperationContract]
[WebInvoke(Method="GET")]
string HelloWorld_GET();
}
}WCF实现:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Proprietary.Framework;
using Proprietary.WebSupport;
using System.Web.Script.Serialization;
namespace Proprietary.WebServices
{
/// <summary>
/// Represents a doclink web service session - Rest version.
/// </summary>
public class Session_REST : ISession_REST
{
string ISession_REST.HelloWorld_POST()
{
return "Hellow World via POST";
}
string ISession_REST.HelloWorld_GET()
{
return "Hello World via GET";
}
}
}发布于 2012-08-22 03:05:47
好的-所以结果是我没有注意到端点地址-它是xmlService -所以我可以从localhost:8002/Session_REST/xmlService/HelloWorld_GET.调用它
服务方法=baseaddress/endpointaddress/ method method/
https://stackoverflow.com/questions/12059921
复制相似问题