【发布时间】:2017-07-24 12:51:14
【问题描述】:
请我们帮我解决这个问题: 我正在用 C# 在 REST 中创建一个 Web 服务 WCF,而不是 SOAP,使用像 https://..../ForMobile.svc/getUsersSMI/params 这样的方法,我想用 PHP 调用这个 Web 服务,我的方法在输入中有一个参数。
【问题讨论】:
标签: c# php web-services wcf web
请我们帮我解决这个问题: 我正在用 C# 在 REST 中创建一个 Web 服务 WCF,而不是 SOAP,使用像 https://..../ForMobile.svc/getUsersSMI/params 这样的方法,我想用 PHP 调用这个 Web 服务,我的方法在输入中有一个参数。
【问题讨论】:
标签: c# php web-services wcf web
您需要为 wcf 服务定义 webHttpBinding 绑定,使其成为一个完整的 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
【讨论】:
谢谢大家,这是我调用 REST WCF 的 PHP 代码:
$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 中有参数时,我没有得到响应,在其他信息中,我使用邮递员进行测试
【讨论】: