我在IIS上部署了我的wcf服务(dot NET)。当我使用一个参数调用API的服务时,它不会返回任何内容。有趣的是,只有当我调用的API具有参数时才会发生这种情况。我们从PHP文件调用webservice。我们将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
答案 0 :(得分: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);