[英]How do you make an HTTP request to a WCF Service Application hosted with IIS?
首先,我对服务器和网络的总体了解很少,因此,如果我说的任何内容不正确或缺少简单的内容,我深表歉意。
我目前正在尝试创建WCF服务应用程序,可以从同一网络上的其他设备发出HTTP请求,并接收JSON形式的响应。 当我使用Visual Studio Development Server托管应用程序时,我能够向本地主机发出这些请求并获得响应。
请求:
http://localhost:15021/Service1.svc/getData/myValue
响应:
{"GetDataResult":"You entered: myValue"}
运营合同:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getData/{value}")]
string GetData(string value);
尽管这在我的机器上可行,但是如果我尝试使用另一台机器,用机器的IP地址更改localhost,则不会得到任何响应。 我开始研究此功能,如果我想要此功能,似乎需要将其托管在IIS中。 我发现了很多有关使用IIS托管WCF服务的教程。 http://www.codeproject.com/Articles/550796/A-Beginners-Tutorial-on-How-to-Host-a-WCF-Service 。
这些教程的问题在于,它们总是使用基于控制台的“客户端”来运行合同,而我需要使用HTTP请求来运行合同。 是否有捷径可寻?
提前致谢。
编辑:
我相信我的web.config可能是我的问题所在,但不确定
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name ="MongoWCF.Service1" >
<endpoint address="../Service1.svc"
binding="webHttpBinding"
contract="MongoWCF.IService1"
behaviorConfiguration="webBehavior" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
您需要使用系统IP地址来使用WCF
服务。
您可以共享您的svc文件的链接,该链接看起来像http:// ip address here/Test/Service.svc
客户端可以使用它生成代理并使用您的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.