呼叫由C#从PHP创建的REST WCF服务

问题描述:

我们可以帮助我解决这个问题: 即时创建Web服务WCF与C#在REST中不是SOAP,有些方法如https://..../ForMobile.svc/getUsersSMI/params,我想通过调用此Web服务PHP我的方法在输入中有一个参数。呼叫由C#从PHP创建的REST WCF服务

您需要为wcf服务定义webHttpBinding绑定为restfull wcf服务。样品绑定作为一个

<system.serviceModel> 
    <services> 
    <service name="AndroidWCF.Service1" behaviorConfiguration="ServiceBehaviour"> 
     <!-- Service Endpoints --> 
     <endpoint address="" binding="webHttpBinding" 
     behaviorConfiguration="webBehavior" contract="AndroidWCF.IService1"> 
     <!--<identity> 
      <dns value="localhost"/> 
     </identity>--> 

     </endpoint> 

     <!--<endpoint address="mex" 
     binding="mexHttpBinding" contract="IMetadataExchange"/>--> 
    </service> 

    </services> 

    <behaviors> 
    <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
     <behavior name="webBehavior"> 
     <webHttp /> 
     </behavior> 
    </endpointBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
    multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

,你可以在这里找到完整的指南https://www.codeproject.com/Tips/803009/Configure-WCF-Service-to-REST

+0

谢谢你澄清restfull wcf,但我需要消耗这个RESTfull b Ÿ一个程序PHP客户端 –

+0

一旦它会被安排好,你可以通过PHP使用curl或类似的方式来调用它,它将与其他可以在ajax中使用的url类似。 –

感谢所有,这是我的代码PHP调用REST WCF:

$data = array(
      'query1' => 'parameter1 ', 
      'text' => 'Hi, Message from android example' 
    ); 
    $url = "https://..../Mobile.svc/getParam"; 
    $ch = curl_init ($url); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $data); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: 
    application/json')); 
    $response = curl_exec ($ch);   
    if(!$response){ 
      die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); 
     } 
    curl_close($ch); 
    echo html_entity_decode($response); 

这是我的代码PHP它的工作,但当我有参数在我的WCF我没有得到回应,在其他信息我使用邮递员测试