2012-10-15 85 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(); 
相关问题