[英]PHP call to .NET soap webservice
我知道有很多有關對肥皂Web服務進行php調用的問題和教程,但我不知道它對我如何起作用。
我已經使用兩種非常簡單的方法制作了.NET Windows Communication Foundation Webservice。
我使用了本教程: http : //www.c-sharpcorner.com/UploadFile/dhananjaycoder/four-steps-to-create-first-wcf-service-for-beginners/
我想從PHP調用此方法。 我用單行代碼制作了一個php文檔。 我可以從服務中獲取功能列表,並且可以將一些數據發送到Web服務。 但是,我的Web服務方法中的參數為空,但是仍然觸發了斷點,並且返回值將返回到我的PHP!
我想我錯過了很多有關標頭,參數,安全性以及更多類似內容的信息。 有人可以告訴我我想念什么,我應該怎么做嗎?
我的服務合同:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace Service
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICalculator" in both code and config file together.
[ServiceContract]
public interface ICalculator
{
[OperationContract]
double AddNumbers(double number1, double number2);
[OperationContract]
double SubstractNumbers(double number1, double number2);
[OperationContract]
double MultiplyNumbers(double number1, double number2);
[OperationContract]
double DivisionNumbers(double number1, double number2);
}
}
我的服務:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace Service
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Calculator" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Calculator.svc or Calculator.svc.cs at the Solution Explorer and start debugging.
public class Calculator : ICalculator
{
public double AddNumbers(double number1, double number2)
{
double result = number1 + number2;
return result;
}
public double SubstractNumbers(double number1, double number2)
{
double result = number1 - number2;
return result;
}
public double MultiplyNumbers(double number1, double number2)
{
double result = number1 * number2;
return result;
}
public double DivisionNumbers(double number1, double number2)
{
double result = number1 / number2;
return result;
}
}
}
Web.Config中
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Service.Calculator">
<endpoint address="" contract="Service.ICalculator" binding="basicHttpBinding"/>
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/>
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
PHP
<?php
try{
echo '<pre>';
$client = new SoapClient('http://localhost:1336/Calculator.svc?wsdl');
print_r($client->AddNumbers(12,21));
}catch(Exception $e){
echo 'Exception: '. $e->getMessage() .'\n';
}
?>
您的WebConfig文件指定一個HTTPS協議:
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
然后PHP嘗試在HTTP上進行連接:
$client = new SoapClient('http://localhost:1336/Calculator.svc?wsdl');
嘗試更改一個或另一個,使它們匹配。
首選使用HTTP進行測試,以避免潛在的證書問題。
另外, AddNumbers
方法期望接收兩個參數。
double AddNumbers(double number1, double number2);
這些沒有在PHP調用中提供。
print_r($client->AddNumbers());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.