0

我正在编写 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
    }
4

1 回答 1

0

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

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

…</p>

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

…</p>

 <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

问候,

于 2013-10-25T11:52:05.297 回答