2012-04-26 3 views
0

나는 wcf를 배우고 샘플 예제로 작업 중이다. 이것에서, 나는 wcf 서비스를위한 dll과 서비스와 다른 클라이언트 appn을 호스팅하기위한 2 개의 윈도우 애플리케이션을 만들었다. appn 호스팅에서 servicehost.open 메서드 다음에 코드를 실행할 수 없습니다. 나는 무슨 일이 일어나고 있는지 궁금해. 도와주세요.servicehost.open 메서드가 실행되지 않는 코드

호스팅 APPN의 코드는 다음과 같습니다 :

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.ServiceModel; 
using System.ServiceModel.Description; 
using WCFService; 
namespace WCFServiceHost 
{ 
    public partial class Form1 : Form 
    { 
     ServiceHost sh = null; 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     private void Form1_Load(object sender, EventArgs e) 
     { 
      Uri tcpa = new Uri("net.tcp://localhost:8000/TcpBinding"); 

      sh = new ServiceHost(typeof(ServiceClass), tcpa); 
      NetTcpBinding tcpb = new NetTcpBinding(); 
      ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior(); 
      sh.Description.Behaviors.Add(mBehave); 
      sh.AddServiceEndpoint(typeof(IMetadataExchange), 
      MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); 
      sh.AddServiceEndpoint(typeof(IServiceClass), tcpb, tcpa); 
      sh.Open(); 
**//This line is not executed 
      label1.Text = "Service Running"; 
//This line is not executed** 
     } 
     private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
     { 
      sh.Close(); 
     } 
    } 
} 

하나 더 도움 : 2005

+0

왜 그 행을 실행할 수 없습니까? 서비스를 시작할 때 예외가 있습니까? 이게 뭐야? –

+0

안녕하세요, Maciej 전 excepiton 로그를 복사했습니다. 아래 문의 사항을 확인하십시오. – chaitanyat

+0

이미 포트 8000에서 청취하고있는 것이 없습니까? – BugFinder

답변

1

2 가지 가능성이 얼마나 우리가 Visual Studio에서 서비스 참조를 추가 할 수 있습니다

  • Form1_Load가 호출되지 않습니다.
  • sh.Open() 또는 이전 줄 중 하나에서 예외가 throw됩니다.

코드 주위에 try catch를 배치하십시오. catch 블록에서 텍스트를 예외 텍스트로 설정하십시오.

편집

이것은 권한 문제입니다. sh.Open() 할 때 프로그램은 포트에서 청취를 시작해야합니다. 포트를 경청하는 것은 허가가 필요합니다.

"관리자 권한으로 실행"으로 프로그램을 시작하면 제대로 작동합니다.

+0

안녕하세요 mr shiraz, 예외 로그입니다. 나는 전체가 상자의 한계를 초과함에 따라 여러 주석 상자에서 이것을 wiriting하고있다. System.ServiceModel.CommunicationException : IP 끝점 = 0.0.0.0 : 8000에서 수신 대기하는 동안 TCP 오류 (10013 : 액세스 권한으로 금지 된 방식으로 소켓에 액세스하려고 시도했습니다.)가 발생했습니다. ---> System.Net.Sockets.SocketException : System.Net.Sockets.Socket.DoBind (EndPoint endPointSnapshot, SocketAddress socketAddress)의 액세스 권한 – chaitanyat

+0

에 의해 금지 된 방식으로 소켓에 액세스하려고했습니다. at System. System.ServiceModel.Channels.SocketConnectionListener.Listen에서 System.ServiceModel.Channels.SocketConnectionListener.Listen() --- 내부 예외 스택 추적의 끝 --- 에서 Net.Sockets.Socket.Bind (를 EndPoint localEP) () System.ServiceModel.Channels.TransportManager.Open (TransportChannelListener channelListener)에서 System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()에서 System.ServiceModel.Channels.BufferedConnectionListener.Listen()에서 – chaitanyat

+0

는 예외가 발생 sh.open 메트 od. 예외 로그를 ​​ – chaitanyat

관련 문제