繁体   English   中英

从PHP调用C#创建的REST WCF服务

[英]Call REST WCF-Service creating by C# from PHP

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

您需要将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

谢谢大家,这是我的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中有参数时,我没有响应,在其他信息中,我使用邮递员进行测试

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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