简体   繁体   中英

Call REST WCF-Service creating by C# from PHP

请为我们解决这个问题,我们可以帮助我:我在REST中使用C#创建Web服务WCF,而不是使用https://..../ForMobile.svc/getUsersSMI/params这样的方法在SOAP中创建Web服务,我想调用此Web服务通过PHP,我的方法在输入中有一个参数。

you need to define webHttpBinding binding for wcf service to be a restfull wcf service. sample bindings are as

<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>

you can find complete guide here https://www.codeproject.com/Tips/803009/Configure-WCF-Service-to-REST

thanks for all, this is my code PHP to call 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); 

this my code PHP it's work but when i have param in my WCF i don't got response, in other information i use postmen for test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM