2014-09-28 82 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