Я создал службу WCF на своем локальном компьютере и размещаю службу в IIS, чтобы я мог вызвать мою службу WCF с другого ПК. Оба компьютера находятся под одним и тем же маршрутизатором. Я могу вызвать службу WCF на своем локальном компьютере, но не могу просматривать одну и ту же услугу с другого ПК.Host WCF Service on Public Ip
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 google эту проблему и нашел много подобных проблем, но не смог понять мою резолюцию. Один thread Я нашел мало полезным, но все еще не смог его получить.
Мой сервисный хост на 192.168.X.XXX:82, когда я просматриваю то же самое на другом ПК, он показывает «Сетевой вопрос». Пожалуйста, помогите мне выбраться отсюда.
Что вы подразумеваете под «просматривать то же самое на другом ПК»? – dotctor
На самом деле я хочу получить доступ к этой Службе в другом проекте, поэтому я хочу попытаться вызвать мой сервис с другого ПК. –
можете ли вы пинговать этот IP-адрес с других компьютеров? – dotctor