2013-08-02 46 views
1

要前言本,我跟一般的服務器和網絡的經驗非常少,所以我很抱歉,如果我說話不正確,或者我失去了一些東西簡單。如何向IIS託管的WCF服務應用程序發出HTTP請求?

我目前正在試圖建立一個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); 

雖然這從我的機器上工作,如果我嘗試了不同的一個,改變localhost通過機器IP地址,我會得不到迴應。我開始研究這個問題,如果我想要這個功能的話,我似乎需要用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> 
+0

Initialy你可以看到從機器的服務託管在IIS? –

+0

在IIS上承載WCF服務非常簡單,在您的WCF webservice項目上右鍵單擊並選擇發佈。只需按照簡單的步驟進行操作即可在IIS上託管WCF服務。稍後使用來自遠程客戶機的相應IP地址的相同服務地址 – dreamweiver

+0

您必須將其公開。之後,嘗試從本地服務器使用它。 –

回答

-1

您需要使用系統的IP地址消耗WCF服務。

你可以分享您的SVC文件,它看起來像http:// ip address here/Test/Service.svc

客戶端可以用它來生成代理和消費服務的鏈接。

相關問題