【问题标题】:WCF POST/GET method with parameters does not return any value带参数的 WCF POST/GET 方法不返回任何值
【发布时间】:2014-09-01 09:44:38
【问题描述】:

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

以下是我的 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>

以下是我的网络服务中的联系人

 [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

【问题讨论】:

    标签: .net wcf iis


    【解决方案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); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 2017-06-05
      • 2017-10-13
      相关资源
      最近更新 更多