如何在delphi中使用post方法使用wcf Rest服务

时间:2016-02-01 06:14:45

标签: c# web-services wcf rest delphi

我有用C#编写的WCF Restful服务,我需要在Delphi中使用该服务。我在服务中使用POST方法作为参数。我的代码是

我的界面代码:

[ServiceContract]
public interface IJsonPostService
{
    [OperationContract]
    [WebInvoke(UriTemplate = "/PlaceOrder",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, Method = "POST")]
    string InsertIntoDB(Employee emp);
}
[DataContract]
public class Employee
{
    [DataMember]
    public string EmpID { get; set; }
    [DataMember]
    public string Empnumber { get; set; }
    [DataMember]
    public string EmpType { get; set; }
    [DataMember]
    public string EmpPassword { get; set; }
}

我的实施

public string InsertIntoDB(Employee Emp)
    {
        return Emp.EmpID+Emp.EmpType;
    }

我的配置文件详细信息

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="SPInsertEDI" value="Insert_EDIDeatils"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="mexBehavior" name="Jsonpost.JsonPostService">
        <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="Jsonpost.IJsonPostService" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="Jsonserice" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

服务运行良好,我可以在C#中使用该服务。但我不想在Delphi中使用它。任何人都可以帮助我使用Delphi代码。

0 个答案:

没有答案