セルフ ホステッド サービスを作成する最初の数回の試み。クエリ文字列を受け入れてテキストを返す何かを作成しようとしていますが、いくつかの問題があります。
すべてのドキュメントでは、エンドポイントが構成ファイルに見つからない場合、各ベース アドレスに対して自動的に作成されるエンドポイントについて説明しています。これは私には当てはまらないようです.「サービスにはアプリケーションエンドポイントがありません...」という例外が発生します。以下のようにベース エンドポイントを手動で指定すると、これが解決されるようです。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Description; namespace TestService { [ServiceContract] public interface IHelloWorldService { [OperationContract] string SayHello(string name); } public class HelloWorldService : IHelloWorldService { public string SayHello(string name) { return string.Format("Hello, {0}", name); } } class Program { static void Main(string[] args) { string baseaddr = "http://localhost:8080/HelloWorldService/"; Uri baseAddress = new Uri(baseaddr); // Create the ServiceHost. using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress)) { // Enable metadata publishing. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(smb); host.AddServiceEndpoint(typeof(IHelloWorldService), new BasicHttpBinding(), baseaddr); host.AddServiceEndpoint(typeof(IHelloWorldService), new BasicHttpBinding(), baseaddr + "SayHello"); //for some reason a default endpoint does not get created here host.Open(); Console.WriteLine("The service is ready at {0}", baseAddress); Console.WriteLine("Press <Enter> to stop the service."); Console.ReadLine(); // Close the ServiceHost. host.Close(); } } } }
このように要求されたときに、SayHello(文字列名) の名前の値を返すように設定するにはどうすればよいでしょうか: localhost:8080/HelloWorldService/SayHello?name=kyle
走る前に歩こうとしているのに、這い回っているようにしか見えない...