0

この例に従って、最初のWCFサービスであるWCF RESTサービスJSONを作成し、それを編集して独自のサービスを作成しました。ASP.NET Developer Serverを使用したデバッグで、サービスを正常に実行することができました。ポート8081(サーバー、ファイアウォール、ルーター上)を開き、IISの[登録]フォルダーに割り当てました。次に、MsDeployAgentServiceを使用する必要があることを理解した後、IIS6を実行しているWindowsServer2003にサービスを公開しました。次に、IISを使用してASP.NETのバージョンを4.0.3019に設定しました。Registrationフォルダーには、Service1.svc、Web.config、およびbinフォルダーが含まれています。

これは私のWeb設定ファイルです:

<?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");

ポートを削除すると、エラー401「許可されていません」が表示されます

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

LANIPとWANIPアドレスを使ってみました。

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;
        }

    }
}
4

2 に答える 2

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();
于 2012-10-15T22:53:26.320 に答える
0

サービスに IIS 6.0 を使用する場合、URL にフォルダー名を含める必要はありませんでした。したがって、コードを1行変更するだけで問題が解決しました。

byte[] data = client.DownloadData("http://ServerIP:8081/Service1.svc/CheckSoftware/1/Customer1/1_0/abc123/1/1");
于 2012-10-17T13:13:30.477 に答える