Asp.net WCF REST通过控制台应用程序
我正在尝试联系控制台应用程序中托管的基本REST服务(由于我们产品的特定原因,我们无法在IIS中托管)。我可以访问localhost:8002/Session\u REST/,wsdl显示得很好。但是如果我尝试localhost:8002/Session\u REST/HelloWorld\u GET或localhost:8002/Session\u REST/HelloWorld\u GET/,我得到的只是一个405错误:找不到方法 应用程序配置:Asp.net WCF REST通过控制台应用程序,asp.net,wcf,rest,console-application,Asp.net,Wcf,Rest,Console Application,我正在尝试联系控制台应用程序中托管的基本REST服务(由于我们产品的特定原因,我们无法在IIS中托管)。我可以访问localhost:8002/Session\u REST/,wsdl显示得很好。但是如果我尝试localhost:8002/Session\u REST/HelloWorld\u GET或localhost:8002/Session\u REST/HelloWorld\u GET/,我得到的只是一个405错误:找不到方法 应用程序配置: <?xml version="1.0"
<?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>
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";
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Runtime.Serialization;
使用System.ServiceModel;
使用System.ServiceModel.Activation;
使用System.ServiceModel.Web;
使用系统文本;
使用专有框架;
使用专有的.WebSupport;
使用System.Web.Script.Serialization;
命名空间专有.WebServices
{
///
///表示doclink web服务会话-Rest版本。
///
公共课课时休息:I课时休息
{
字符串ISession\u REST.HelloWorld\u POST()
{
通过POST返回“Hellow World”;
}
字符串ISession\u REST.HelloWorld\u GET()
{
通过GET返回“Hello World”;
}
}
}
好的-原来我没有注意端点地址-它是xmlService-所以我可以从localhost调用它:8002/Session\u REST/xmlService/HelloWorld\u GET
服务方法=baseaddress/endpointaddress/methodname/
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";
}
}
}