2015-01-11 2 views
0

내 로컬에서 WCF 서비스를 만들고 IIS에서 서비스를 호스팅하여 다른 PC에서 내 WCF 서비스를 호출 할 수 있습니다. 두 PC 모두 동일한 라우터 아래에 있습니다. 내 지역에서는 WCF 서비스에 전화를 걸 수 있지만 다른 PC에서 동일한 서비스를 탐색 할 수는 없습니다.공용 IP에서 호스트 WCF 서비스

의 Web.config

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use 
    the Website->Asp.Net Configuration option in Visual Studio. 
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
--> 
<configuration> 
    <appSettings /> 
    <connectionStrings /> 
    <system.web> 
    <!-- 
      Set compilation debug="true" to insert debugging 
      symbols into the compiled page. Because this 
      affects performance, set this value to true only 
      during development. 
     --> 
    <compilation debug="true" targetFramework="4.0" /> 
    <!-- 
      The <authentication> section enables configuration 
      of the security authentication mode used by 
      ASP.NET to identify an incoming user. 
     --> 
    <authentication mode="Windows" /> 
    <!-- 
      The <customErrors> section enables configuration 
      of what to do if/when an unhandled error occurs 
      during the execution of a request. Specifically, 
      it enables developers to configure html error pages 
      to be displayed in place of a error stack trace. 

     <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> 
      <error statusCode="403" redirect="NoAccess.htm" /> 
      <error statusCode="404" redirect="FileNotFound.htm" /> 
     </customErrors> 
     --> 
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /> 
    </system.web> 
    <system.web.extensions> 
    <scripting> 
     <webServices> 
     <!-- 
       Uncomment this section to enable the authentication service. Include 
       requireSSL="true" if appropriate. 

      <authenticationService enabled="true" requireSSL = "true|false"/> 
      --> 
     <!-- 
       Uncomment these lines to enable the profile service, and to choose the 
       profile properties that can be retrieved and modified in ASP.NET AJAX 
       applications. 

      <profileService enabled="true" 
          readAccessProperties="propertyname1,propertyname2" 
          writeAccessProperties="propertyname1,propertyname2" /> 
      --> 
     <!-- 
       Uncomment this section to enable the role service. 

      <roleService enabled="true"/> 
      --> 
     </webServices> 
     <!-- 
     <scriptResourceHandler enableCompression="true" enableCaching="true" /> 
     --> 
    </scripting> 
    </system.web.extensions> 
    <!-- 
     The system.webServer section is required for running ASP.NET AJAX under Internet 
     Information Services 7.0. It is not necessary for previous version of IIS. 
    --> 
    <system.serviceModel> 
     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <services>   
     <service name="WcfStudentService.StudentService" behaviorConfiguration="WcfStudentService.StudentServiceBehavior"> 
     <!-- Service Endpoints --> 
     <endpoint address="" binding="wsHttpBinding" contract="WcfStudentService.IStudentService"> 
      <!-- 
       Upon deployment, the following identity element should be removed or replaced to reflect the 
       identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
       automatically. 
      --> 
      <identity> 
      <dns value="localhost" /> 
       <!--<dns value="123.236.41.136" />--> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WcfStudentService.StudentServiceBehavior"> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true" /> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors>  
    </system.serviceModel> 
    <system.webServer> 
     <defaultDocument> 
      <files> 
       <add value="StudentService.svc" /> 
      </files> 
     </defaultDocument> 
    </system.webServer> 
</configuration> 

StudentService.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace WcfStudentService 
{ 
    // StudentService is the concrete implmentation of IStudentService. 
    public class StudentService : IStudentService 
    { 
     List<StudentInformation > Students = new List<StudentInformation>() ; 

     // Create list of students 
     public StudentService() 
     { 
      Students.Add(new StudentInformation(1001, "Nikhil", "Vinod")); 
      Students.Add(new StudentInformation(1002, "Joshua", "Hunter")); 
      Students.Add(new StudentInformation(1003, "David", "Sam")); 
      Students.Add(new StudentInformation(1004, "Adarsh", "Manoj")); 
      Students.Add(new StudentInformation(1005, "HariKrishnan", "Vinayan")); 
     } 

     // Method returning the Full name of the student for the studentId 
     public string GetStudentFullName(int studentId) 
     { 
      IEnumerable<string> Student 
         = from student in Students 
          where student.StudentId == studentId 
          select student.FirstName + " " + student.LastName; 

      return Student.Count() != 0 ? Student.First() : string.Empty; 
     } 

     // Method returning the details of the student for the studentId 
     public IEnumerable<StudentInformation> GetStudentInfo(int studentId) 
     { 

      IEnumerable<StudentInformation> Student = from student in Students 
                 where student.StudentId == studentId 
                 select student ; 
      return Student; 
     } 


    } 
} 

IStudentService.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 

namespace WcfStudentService 
{ 
    // Defines IStudentService here 
    [ServiceContract ] 
    public interface IStudentService 
    { 

     // Define the GetStudentFullName OperationContact here…. 
     [OperationContract] 
     String GetStudentFullName(int studentId); 

     // Define the GetStudentInfo OperationContact here…. 
     [OperationContract] 
     IEnumerable<StudentInformation> GetStudentInfo(int studentId); 

    } 


    // Use a data contract as illustrated in the sample below to add composite types to service operations. 
    [DataContract] 
    public class StudentInformation 
    { 
     int _studentId ; 
     string _lastName; 
     string _firstName; 

     public StudentInformation(int studId, string firstname, string lastName) 
     { 
      _studentId = studId; 
      _lastName = lastName; 
      _firstName = firstname; 
     } 

     [DataMember] 
     public int StudentId 
     { 
      get { return _studentId; } 
      set { _studentId = value; } 
     } 

     [DataMember] 
     public string FirstName 
     { 
      get { return _firstName; } 
      set { _firstName = value; } 
     } 

     [DataMember] 
     public string LastName 
     { 
      get { return _lastName; } 
      set { _lastName = value; } 
     } 
    } 
} 

I 구글이 문제를 발견하고 비슷한 문제가 많이 있지만 내 해상도를 이해할 수 없습니다. One thread 조금 도움이되었지만 아직도 얻을 수 없었습니다.

내 서비스 호스트가 192.168.X.XXX:82에 있습니다. 다른 PC에서 동일한 서비스를 검색하면 "네트워크 문제"가 표시됩니다. 이 일에서 빠져 나가도록 도와주세요.

+0

"다른 PC에서 같은 것을 찾으십시오"라는 것은 무엇을 의미합니까? – dotctor

+0

실제로 다른 프로젝트에서이 서비스에 액세스하여 다른 PC에서 내 서비스를 호출하려고합니다. –

+0

다른 컴퓨터에서 해당 IP 주소로 핑 (ping) 할 수 있습니까? – dotctor

답변

0

내 시스템에 인바운드 및 아웃 바운드 규칙을 추가하고 "도메인, 개인 및 공용"에 대해 포트 82를 허용합니다. 규칙 "제어판 -> 모든 제어판 항목 -> Windows 방화벽 -> 고급 설정"을 설정할 수 있습니다.

희망이 있으면 도움이됩니다.

관련 문제