2014-09-01 72 views
0

我已经在IIS上部署了我的wcf服务(dot NET)。当我使用一个参数调用API的服务时,它不会返回任何内容。有趣的是,只有当我调用的API有参数时才会发生这种情况。我们从一个PHP文件调用webservice。我们将PHP的链接提供给客户端(javascript)。带参数的WCF POST/GET方法不返回任何值

以下是我的web.config

<!-- Service Endpoints --> 
    <!-- Unless fully qualified, address is relative to base address supplied above --> 
    <endpoint address="" binding="webHttpBinding" contract="WcfServiceLibrary1.IService1" behaviorConfiguration="Web"> 
     <!-- 
      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. 
     --> 
    </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 name="ServiceBehaviour"> 
     <!-- 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="True" /> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="Web"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> </system.serviceModel> 
<system.webServer> 
    <directoryBrowse enabled="true" /> 
</system.webServer> </configuration> 

以下是我的web服务接触

[ServiceContract(Namespace = "http://xomw764dei.dsone.3ds.com/IPDWSRest/Service1.svc")] 
     public interface IService1 
     { 
      [OperationContract] 
      [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/getData", ResponseFormat = WebMessageFormat.Xml, Method = "GET")] 
      string GetData(); 

      [OperationContract] 
      CompositeType GetDataUsingDataContract(CompositeType composite); 

      [OperationContract] 
      [FaultContract(typeof(ExceptionOnIPDWS))] 
      [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/getAllServerMachines{poolingServer}", ResponseFormat = WebMessageFormat.Xml, Method = "GET")] 
      //pServerName getAllServerMachines(string poolingServer); 
      string getAllServerMachines(string poolingServer); 

      [OperationContract] 
      [FaultContract(typeof(ExceptionOnIPDWS))] 
      [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/getServerUtil", ResponseFormat = WebMessageFormat.Xml)] 
      Status getServerUtil(string poolingServer,string serverPID, ref string oCreateResult); 



      // TODO: Add your service operations here 
     } 

我的PHP文件看起来像这样

<?php 
$url = 'http://xomw764dei/IPDWSRest/Service1.svc/getData'; 
//$url = func_get_arg(0); 
$callback = $_GET["callback"]; 

echo($callback . "("); 
    echo(file_get_contents($url)); 
echo (")"); 
?> 



<?php 
$url = 'http://xomw764dei/IPDWSRest/Service1.svc/getAllServerMachines'; 
//$url = func_get_arg(0); 
$callback = $_GET["callback"]; 

echo($callback . "("); 
echo(file_get_contents($url . '/' . $_POST["poolingServer"])); 
echo (")"); 
?> 

现在在浏览器中第一次调用效果很好 的http://:1136 /访问getdata.php

但是第二次通话不会返回任何数据

HTTP://:1136/ServerTools.php poolingServer = thunderw7dei

回答

1

UriTemplate应该是这样的:

[OperationContract] 
     [FaultContract(typeof(ExceptionOnIPDWS))] 
     [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/getAllServerMachines/{poolingServer}", ResponseFormat = WebMessageFormat.Xml, Method = "GET")] 
     //pServerName getAllServerMachines(string poolingServer); 
     string getAllServerMachines(string poolingServer);