什么应该是WCF HTTP Post的URI?

时间:2013-10-25 09:03:38

标签: .net wcf

我正在编写WCF HTTP POST,以下是服务合同,我应该怎么做才能使用服务的URI?

  [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebInvoke(UriTemplate = "/JsonData",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        bool SendData(JsonString JsonImage);

        // TODO: Add your service operations here
    }

1 个答案:

答案 0 :(得分:0)

您的WCF服务很可能具有定义服务主机绑定,行为和端点元素的配置文件。因此,URL应该是服务基地址和UriTemplate的组合。以下配置文件片段提供了我们的一个wcf https休息服务的参考样本:

<bindings>
  <webHttpBinding>
    <binding name="RestBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>

...

    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultServiceBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceCredentials>
           …
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>

...

 <service name="TestRest">
    <endpoint behaviorConfiguration="RestBehavior" binding="webHttpBinding"
      bindingConfiguration="RestBinding" name="RestServiceEndpoint"
      contract="Test.Rest.Interface" />
    <host>
      <baseAddresses>
        <add baseAddress="http://domain.name.here:18100/" />
      </baseAddresses>
    </host>
  </service>

因此,URL将是: http://domain.name.here:18100/JsonData

此致