如何从远程php服务器访问WCF自托管服务

时间:2014-09-28 13:10:06

标签: c# php wcf remote-server

我使用C#应用程序创建了自托管WCF服务。我想从远程php服务器向C#应用程序发送消息。我该如何执行此功能?

<?xml versio="1.0"?>      
<configuration><system.serviceModel>      
  <services>       
    <service name="MyMathServiceLib.MyMathService" behaviorConfiguration="myMathServiceBehave">       
      <host>       
        <baseAddresses>       
          <add baseAddress="http://localhost:9001/MyMathService"/>       
          <add baseAddress="net.tcp://localhost:9002/MyMathService"/>       
        </baseAddresses>       
      </host>       
      <endpoint address="http://localhost:9001/MyMathService" binding="basicHttpBinding"   contract="MyMathServiceLib.IMyMathService"/>       
      <endpoint address="net.tcp://localhost:9002/MyMathService" binding="netTcpBinding"   contract="MyMathServiceLib.IMyMathService"/>       
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>       
      <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>       
    </service>       
  </services>       
  <behaviors>       
    <serviceBehaviors>       
      <behavior name="myMathServiceBehave">       
        <serviceMetadata httpGetEnabled="true"/>       
      </behavior>       
    </serviceBehaviors>       
  </behaviors>       
</system.serviceModel>       
</configuration>

这是我的app.config文件(参考:http://www.codeproject.com/Articles/650869/Creating-a-Self-Hosted-WCF-Service

我的目标是从php服务器向c#application

发送消息

1 个答案:

答案 0 :(得分:0)

按照简单的步骤:

  1. 在visual studio文件夹中,您应该看到WCF客户端。
  2. 将您的WCF网址添加到此客户端(在您的情况下为http://localhost:9001/MyMathService)。在请求中填写示例数据,然后单击&#34; XML&#34;。
  3. 复制XML并将其放在PHP中的变量中。而不是您在上一步中放入的虚拟值,而是放入适当的PHP变量。
  4. 启用PHP CURL。将此变量POST到WCF服务。
相关问题