小编Max*_*nev的帖子

在运行时创建WCF服务时出现ActionNotSupported错误

我试图WCF在运行时创建一个服务.我的服务界面是:

[ServiceContract]
public interface IInformationService : IService
{
    [OperationContract]
    [WebInvoke(Method = "Get", ResponseFormat = WebMessageFormat.Json, 
     UriTemplate = "Test",     RequestFormat  = WebMessageFormat.Json)]
    string Test();
}
Run Code Online (Sandbox Code Playgroud)

我服务的服务如下:

var httpEnumerator = ImplementedContracts.Values.GetEnumerator();
httpEnumerator.MoveNext();

var httpContractType = httpEnumerator.Current.ContractType;
var webBinding = new WebHttpBinding()
                 {
                   Security =
                   {
                     Mode = WebHttpSecurityMode.None
                   }
                 };

var httpEndpoint = AddServiceEndpoint(
  httpContractType, 
  webBinding, baseAddress+/Get"
);

httpEndpoint.Behaviors.Add(new CustomEndpointBehavior());
Run Code Online (Sandbox Code Playgroud)

ServiceHost由此方法创建:

protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
  var host = new WcfServiceHost(serviceType, baseAddresses);

  if (host.Description.Behaviors.Contains(typeof(ServiceDebugBehavior)))
  {
    (host.Description.Behaviors[typeof(ServiceDebugBehavior)] as …
Run Code Online (Sandbox Code Playgroud)

c# wcf wcf-binding

7
推荐指数
1
解决办法
5421
查看次数

标签 统计

c# ×1

wcf ×1

wcf-binding ×1