soapURL通过PHP中的Soap调用C #Windows服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了soapURL通过PHP中的Soap调用C #Windows服务相关的知识,希望对你有一定的参考价值。

问题:

我继承了一个用php调用C#windows服务的软件。它不能正常工作,所以我刚刚开始使用WCF和SOAP。

我的主要问题是我无法使用PHP和Soap调用Windows服务。当我尝试它时,PHP崩溃了。

我完成了微软教程:https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial当我使用教程中描述的C#客户端时,一切都像魅力一样。我添加了一个安装程序,使整个程序可用作Windows服务。长话短说,在C#中,一切都按预期运行。

我假设它没有正确配置SOAP调用。我已经读完了:http://www.rizalalmashoor.com/blog/calling-a-wcf-service-from-php/但我仍然无法让它运行。

问题:

源代码在下面。我想先提出问题:

1)我在基地址公开服务,对吧?

HTTP://本地主机:1234 / GettingStartedLib / CalculatorService的

2)http端点为空。我的soapURL在PHP代码中是否正确?

3)有没有办法调试肥皂电话?即使我在ZendStudio中将其作为CLI应用程序进行调试,我也无法获得任何进一步的信息。

如果需要,我很乐意提供进一步的信息,或者没有充分解释。

  • 在有人回答之前:在php.ini中启用了肥皂。已经检查过了。

源代码:

PHP:

$soapURL = 'http://localhost:1234/GettingStartedLib/CalculatorService?wsdl';
$soapAttributes = array('soap_version' => SOAP_1_1);

$result = new SoapClient($soapURL, $soapAttributes);

WCF库的配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="GettingStartedLib.CalculatorService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:1234/GettingStartedLib/CalculatorService"/>
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="GettingStartedLib.ICalculator">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <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>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
  </startup>
</configuration>

C#界面

namespace GettingStartedLib
{
    [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
    public interface ICalculator {
        [OperationContract]
        double Add(double n1, double n2);
        [OperationContract]
        double Subtract(double n1, double n2);
        [OperationContract]
        double Multiply(double n1, double n2);
        [OperationContract]
        double Divide(double n1, double n2);
        [OperationContract]
        string SoapCall();
    }
}

C#服务本身:

namespace GettingStartedLib
{
    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2) {
            double result = n1 + n2;
            Console.WriteLine("Received Add({0},{1})", n1, n2);
            // Code added to write output to the console window.  
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        public double Subtract(double n1, double n2) {
            double result = n1 - n2;
            Console.WriteLine("Received Subtract({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        public double Multiply(double n1, double n2) {
            double result = n1 * n2;
            Console.WriteLine("Received Multiply({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }

        public double Divide(double n1, double n2) {
            double result = n1 / n2;
            Console.WriteLine("Received Divide({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }
        public string SoapCall() => "SoapCall";
    }
}
答案

解决了这个问题。我不得不进入

<baseAddresses><add baseAddress="localhost:1234/GettingStartedLib/CalculatorService.vsc"/>
</baseAddresses>

由于我将http端点的地址留空,因此soap URL为localhost:1234/GettingStartedLib/CalculatorService.vsc?wsdl

以上是关于soapURL通过PHP中的Soap调用C #Windows服务的主要内容,如果未能解决你的问题,请参考以下文章

WSO2 ESB调用SOAP端点无法执行操作

php下调用soap实现对接

需要了解PHP中的SOAP 1.2 Web服务数据调用/发送

php 如何利用 soap调用.Net的WebService asmx文件

在php中调用soap函数时出错

通过 SOAP 实现 GMT php 或 UTC C# 等价