2012-10-15 102 views
0

我跟着這個例子,使我的第一個WCF服務:WCF REST Service JSON,然後編輯它來創建我自己的。我能夠讓我的服務在使用ASP.NET Developer Server進行調試時運行良好。我打開了端口8081(在服務器,防火牆和路由器上),然後將其分配給IIS中的「註冊」文件夾。然後,我花了一天的時間找出我必須使用MsDeployAgentService後,將服務發佈到運行IIS 6的Windows Server 2003。然後我使用IIS將ASP.NET版本設置爲4.0.3019。註冊文件夾包含Service1.svc,Web.config和bin文件夾。WCF REST JSON服務返回錯誤404 /例外:System.Web.HttpException(0x80004005)

這是我的網絡配置文件:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    </configSections> 
    <connectionStrings> 
    <add name="ServiceApp.Properties.Settings.RegistrationConnection" 
     connectionString="Data Source=EDITED;Initial Catalog=Registration;Persist Security Info=True;User ID=EDITED;Password=EDITED;MultipleActiveResultSets=True" /> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime maxRequestLength="524288" /> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="StreamedRequestWebBinding" 
       bypassProxyOnLocal="true" 
       useDefaultWebProxy="false" 
       hostNameComparisonMode="WeakWildcard" 
       sendTimeout="10:15:00" 
       openTimeout="10:15:00" 
       receiveTimeout="10:15:00" 
       maxReceivedMessageSize="2147483647" 
       maxBufferSize="2147483647" 
       maxBufferPoolSize="2147483647" 
       transferMode="StreamedRequest"> 
      <readerQuotas maxArrayLength="2147483647" 
         maxStringContentLength="2147483647" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <services> 
     <service name="ServiceApp.Service1" behaviorConfiguration="ServiceBehaviour"> 
     <endpoint address="" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract="ServiceApp.IService1" behaviorConfiguration="web"> 
     </endpoint> 
      </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

當我嘗試使用了測試客戶端的服務,我得到錯誤404用下面的語句

byte[] data = client.DownloadData("http://ServerIP:8081/Registration/Service1.svc/CheckSoftware/1/Customer1/1_0/abc123/1/1"); 

當我刪除端口I得到一個錯誤401「未經授權」

byte[] data = client.DownloadData("http://ServerIP/Registration/Service1.svc/CheckSoftware/1/Customer1/1_0/abc123/1/1"); 

我已經嘗試使用LAN IP和WA N IP地址。

跟隨this post,因爲它看起來很喜歡OP遵循相同的例子,並有西米拉問題,但它沒有幫助。

我然後看着在事件查看器在服務器上,發現這個時候我包含在端口號:

WebHost failed to process a request. 
Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/23878916 
Exception: System.Web.HttpException (0x80004005): The service '/Registration/Service1.svc' does not exist. ---> System.ServiceModel.EndpointNotFoundException: The service '/Registration/Service1.svc' does not exist. 
    at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) 
    at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath) 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() 
    at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) 
Process Name: w3wp 


Process ID: 3460 

我可以清楚地看到Service1.svc文件存在文件夾中。我很迷茫,並希望得到任何幫助。

編輯,包括更多的代碼:

namespace ServiceApp 
{ 
    [ServiceContract] 
    public interface IService1 
    { 

     [OperationContract] 
     [WebInvoke(Method = "GET", 
      UriTemplate = "/CheckSoftware/{SoftwareId}/{CustomerId}/{Version}/{Key}/{MoboID}/{ProcessorID}", 
      RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json)] 
     SoftwareStatus CheckSoftware(string SoftwareID, string Version, string CustomerID, string Key, string moboID, string processorID); 

     [OperationContract] 
     [WebInvoke(
      Method = "GET", 
      UriTemplate = "/SaveKey/{SoftwareId}/{CustomerId}/{Key}/{MoboID}/{ProcessorID}", 
      RequestFormat = WebMessageFormat.Json, 
      ResponseFormat = WebMessageFormat.Json)] 
     string SaveKey(string SoftwareID, string CustomerID, string Key, string moboID, string processorID); 
    } 

    [DataContract] 
    public class FileInformation 
    { 
     [DataMember] 
     public string Name 
     { 
      get; 
      set; 
     } 

     [DataMember] 
     public byte[] Content 
     { 
      get; 
      set; 
     } 
    } 

    [DataContract] 
    public class Employee 
    { 
     [DataMember] 
     public int Id 
     { 
      get; 
      set; 
     } 

     [DataMember] 
     public string Name 
     { 
      get; 
      set; 
     } 
    } 
    [DataContract] 
    public class SoftwareKey 
    { 
     [DataMember] 
     public string SoftwareId 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public string CustomerId 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public string Version 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public string Key 
     { 
      get; 
      set; 
     } 
    } 

    [DataContract] 
    public class SoftwareStatus 
    { 
     [DataMember] 
     public Boolean SoftwareId 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public Boolean CustomerId 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public Boolean Version 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public Boolean Key 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public Boolean HardwareID 
     { 
      get; 
      set; 
     } 

    } 
} 
+0

檢查你的文件結構,你有一個文件夾,在文件中它/Registration/Service1.svc「 – user854301

+0

我有一個名爲登記在其服務器上的文件Service1.svc文件夾C盤 – Calidus

+0

你能從界面向我們展示UriTemplate嗎?實際上向我們展示了裝飾的整個接口聲明。 – Sinaesthetic

回答

0

當使用IIS 6.0作爲服務我不需要在URL中包含文件夾名稱。所以只需更改一行代碼即可解決我的問題。

byte[] data = client.DownloadData("http://ServerIP:8081/Service1.svc/CheckSoftware/1/Customer1/1_0/abc123/1/1"); 
0

是您的UriTemplate設置是否正確? 404錯誤表明它根本沒有與服務/方法聯繫。

REST服務是簡單的Web的API,而不是試圖導入服務,就像您正常的WCF服務,嘗試一個普通的HTTP請求(只是一個光禿禿的例子,而不是解決方案):

//declare the request (not sure of your uri, so i guessed) 
    var queryString = string.Format("1/{0}/1_0/{1}/1/1", Param1, Param2); 
    var req = 
     HttpWebRequest)WebRequest.Create("http://ServerIP:8081/Registration/Service1.svc/CheckSoftware/"); //base address of service 
    req.Method = "POST"; 
    req.ContentType = "application/x-www-form-urlencoded"; 

    //build the fields stream 
    var fields = Encoding.UTF8.GetBytes(queryString); 
    req.ContentLength = fields.Length; 

    //put the request info into the stream 
    var requestStream = req.GetRequestStream(); 
    requestStream.Write(fields, 0, fields.Length); 
    requestStream.Close(); 

    //execute the request 
    var resp = (HttpWebResponse)req.GetResponse(); 

    //pull your infos 
    var statusCode = (int)resp.StatusCode; 
    var body = new StreamReader(resp.GetResponseStream()).ReadToEnd(); 
相關問題