我们可以帮助我解决这个问题: 我在REST中使用C#创建一个Web服务WCF而不是像https://..../ForMobile.svc/getUsersSMI/params这样的一些方法,我希望通过PHP调用这个Web服务,我的方法在输入中有一个参数。
答案 0 :(得分:0)
您需要将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
答案 1 :(得分:0)
感谢所有人,这是我的代码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中有param时我没有得到回复,在其他信息中我使用postmen进行测试