2014-09-28 203 views
-1

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

<?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#应用程序

回答

0

按照简单的步骤:

  1. 在你的Visual Studio文件夹中,你应该看到WCF客户端。
  2. 将您的WCF URL添加到此客户端(您的案例中为http://localhost:9001/MyMathService)。填写请求中的示例数据并点击“XML”。
  3. 复制XML并将其放入PHP中的变量中。而不是你在前面的步骤中输入的虚拟值,放置适当的PHP变量。
  4. 启用PHP CURL。将此变量发布到WCF服务。
+0

无法让你@Jay – Rakesh 2014-09-29 02:22:26

+0

我的php服务器在在线远程服务器上。如何使用localhost – Rakesh 2014-09-29 11:07:11

+0

@Rakesh访问,然后用服务器的ip暴露WCF来替换'localhost'。准确告诉我你无法理解的内容? – 2014-09-29 15:05:44