2011-08-18 2 views
1

콘솔 앱에서 자체 호스팅하고있는 wcf 서비스가 있습니다.코드 전용 WCF 호스팅은 wsdl에 대한 링크에 "localhost"가 있습니다

서비스를 실행하고이를 시스템 (MyWCFRunningMachine이라고 함)에 배치하면 "서비스를 만들었습니다"페이지로 이동할 수 있습니다. (http : // MyWCFRunningMachine : 8090/MyService).

하지만 그러면 wsdl 페이지에 대한 링크가 제공됩니다. 내가 그 링크를 클릭 할 때

은 그래서 MyWCFRunningMachine보다는 내 컴퓨터를 사용하여 서비스에 연결을 시도 8090 /이면 MyService WSDL : HTTP : // localhost를? 그 링크는 다음과 같습니다.

wsdl (http : // MyWCFRunningMachine : 8090/MyService? wsdl) 경로에 콜드 입력하면 브라우저에 wsdl이 표시됩니다. 그러나 서비스 참조를 추가하려고하면 다음 오류가 발생합니다.

The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading 'http://localhost:8090/MyService?xsd=xsd0'.

이 경우 로컬 호스트가 참조되지 않아야합니다. 나는이 로컬 호스트를 제거하는 얻을 수있는 방법

public class SelfServiceHost 
{ 
    static string StartUpUrl {get{return "http://localhost:8090/MyService";}} 
    static void Main(string[] args) { StartupService(StartUpUrl); } 

    public static ServiceHost StartupService(string startUpUrl) 
    { 
     //+ Setup the Service 
     //Create a URI to serve as the base address 
     Uri httpUrl = new Uri(startUpUrl); 
     //Create ServiceHost 
     ServiceHost host = new ServiceHost(typeof(MyService), httpUrl); 
     //Add a service endpoint 
     host.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(), ""); 
     //Enable metadata exchange 
     ServiceMetadataBehavior serviceMetadataBehavior = 
      new ServiceMetadataBehavior {HttpGetEnabled = true}; 
     host.Description.Behaviors.Add(serviceMetadataBehavior); 

     //! Turn on Debug. Remove for production! 
     host.Description.Behaviors.Remove(typeof (ServiceDebugBehavior)); 
     ServiceDebugBehavior serviceDebugBehavior = 
      new ServiceDebugBehavior {IncludeExceptionDetailInFaults = true}; 
     host.Description.Behaviors.Add(serviceDebugBehavior); 

     //Start the Service 
     host.Open(); 
     Console.WriteLine("Service is hosted at " + httpUrl); 
     Console.ReadLine(); 

     return host; 
    } 
} 

: 여기

내가 자기에 사용하고있는 코드가 내 서비스를 호스팅입니까? (참고 : MyWCFRunningMachine에 하드 코딩 할 수 없습니다.이 서비스는 여러 대의 컴퓨터에서 실행됩니다.

컴퓨터를 이동할 때 변경되는 구성 파일을 사용해야합니까? (구성에서 멀리 떨어져 있습니다. 파일을 설정하고 싶지 않았기 때문에 콘솔 앱을 설치하고 싶지는 않지만 그럴만 한 방법이 있다면 내가 할 것입니다.)

답변

1

설정 파일을 사용하여 컴퓨터 이름이 정확하다고 생각합니다.

에 "http : //"+ MACHINE_NAME + ": 8090 /이면 MyService"서비스가 설치되면

는 설정 파일 A의 그 값을 변경 가져올 서비스를 다시 시작하십시오.

관련 문제