WCF应用程序无法正常工作 [英] WCF application don't working
问题描述
来自拉脱维亚的巨著!
我正在使用WCF进行申请.但是它不能正常工作.
所以IService.cs
Greatings from Latvia!
I''m making application with WCF. But it don''t working fine.
so IService.cs
namespace WCFSample
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string MyName(string name);
}
}
Service.cs
Service.cs
namespace WCFSample
{
public class Service1 : IService1
{
public string MyName(string name)
{
return string.Format("My Name... {0}", name);
}
}
}
这是主机ConsoleAplication代码.我添加了对宿主应用程序的引用. (system.ServiceModel和WCFSample
Here is Host ConsoleAplication Code. I have added References to Host aplication. (system.ServiceModel and WCFSample
namespace ConsoleApplication1
{
class Program
{
static ServiceHost customerHost = null;
static void Main(string[] args)
{
try
{
HostCustomerService();
Console.WriteLine();
Console.WriteLine("Press any key to stop the services.");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
customerHost.Close();
}
}
private static void HostCustomerService()
{
customerHost = new ServiceHost(typeof
(Service1));
ServiceEndpoint tcpEndpoint = customerHost.AddServiceEndpoint(
typeof(IService1), new NetTcpBinding(),
"net.tcp://192.168.1.103:9020/Service1");
customerHost.Open();
Console.WriteLine("{0} {1}", tcpEndpoint.Address, tcpEndpoint.Name);
Console.WriteLine();
}
}
}
这是客户端ConsoleAplicaiton
And here is Client ConsoleAplicaiton
namespace Client1
{
class Program
{
static void Main(string[] args)
{
IService1 channel = null;
var endPoint = new EndpointAddress(
"net.tcp://192.168.1.103:9020/Service1");
channel = ChannelFactory<IService1>.CreateChannel(new NetTcpBinding(), endPoint);
Console.WriteLine("Enter Name");
string line = Console.ReadLine();
Console.WriteLine(channel.MyName(line));
Console.ReadKey();
}
}
}
当我在本地主机上运行时,所有工作正常.但是,当我从同一子网中的另一个PC运行客户端应用程序时,>没有什么.客户端程序NotResponding.
我读过许多文献,但找不到答案.有人可以帮我吗?
对不起,我的英语.
英语. :)
感谢您的回答
when I run on localhost all works. But when I run client app from another Pc in same subnet -> nothing. Client programm NotResponding.
I have read many literature and I can not find answers. Can someone help me?
Sorry my english.
english. :)
Thanks for answers
推荐答案
谢谢那些看过我的主题的人.
我已经解决了我的问题.
所以....
在客户端上,我放了Try .... catch块方法(MyName)
那么我可以读取错误.在此之前,该程序已关闭.
Thank you, those guys who looked at my Topic.
I have solved my problem.
SO....
on client I put on Try....catch block method (MyName)
then i could to read the error. before then the program was closed.
try
{
string line = Console.ReadLine();
Console.WriteLine(channel.MyName(line));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
测量的误差为
身份验证期间未满足远程安全要求.尝试提高保护级别和/或模拟级别
然后我在主机应用程序上更改了安全设置
gauged error was
a remote side security requirement was not fulfilled during authentication. TRy increasing the ProtectionLevel and/or ImpersonationLevel
then i changed Security settings on Host app
static NetTcpBinding bbb = new NetTcpBinding();
......
ServiceEndpoint tcpEndpoint = customerHost.AddServiceEndpoint(
typeof(IService1), bbb,
"net.tcp://192.168.1.102:9020/Service1");
bbb.Security.Mode = SecurityMode.None;
并在客户端应用程序上....
And on client app....
NetTcpBinding bbb = new NetTcpBinding();
bbb.Security.Mode = SecurityMode.None;
您是否在托管服务的计算机上检查了防火墙设置?
如果某些东西可以在本地工作,但不能通过网络访问,那是我要检查的第一件事.
have you checked your firewall settings on the machine hosting the service?
if something works local but doesn''t over a network, it''s the first thing I''d check.
这篇关于WCF应用程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!