一个wcf小程序,在我本机测试时 服务器和客户端程序都正常,但把服务器端程序放到另一台机器时就报错::从另一方收到未进行安全处理或安全处理不正确的错误  这是错误信息。
该如何解决?  谢谢服务器端代码: 服务器端只有契约,没配置config文件using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace ServiceModelSamples
{    [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
    public interface ICalculator
    {
        [OperationContract]
        double Add(double n1, double n2);
    }    //实现契约和接口
    public class CalculatorService : ICalculator
    {
        public double Add(double n1, double n2)
        {
            double result = n1 + n2;
            Console.WriteLine("Received Add({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}", result);
            return result;
        }      }    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/ServiceModelSamples");
            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);
            try
            {
                // Add a service endpoint
                serviceHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");
                // Enable metadata exchange
                System.ServiceModel.Description.ServiceMetadataBehavior smb = new System.ServiceModel.Description.ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                serviceHost.Description.Behaviors.Add(smb);
                serviceHost.Open();
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();                // Close the ServiceHostBase to shutdown the service.
                serviceHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occured: {0}", ce.Message);
                serviceHost.Abort();
            }        }
    }
}
客户端代码,客户端包括2个cs文件和一个config文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {            try
            {
                //Create an instance of the WCF Client.
                System.ServiceModel.EndpointAddress epAddress = new EndpointAddress("http://localhost:8000/ServiceModelSamples/ServiceModelSamples/CalculatorService");
                CalculatorClient client = new CalculatorClient(new WSHttpBinding(), epAddress);                             // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);                           client.Close();                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate client.");
                Console.ReadLine();
            }            catch (System.ServiceModel.CommunicationException ex)
            {
                Console.WriteLine(ex.Message);
            }        }
    }
}
app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ICalculator" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" establishSecurityContext="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8000/ServiceModelSamples/ServiceModelSamples/CalculatorService"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
                contract="ICalculator" name="WSHttpBinding_ICalculator">
                <identity>
                    <userPrincipalName  value="CG-LV\admin"/>
              
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

解决方案 »

  1.   

    先把防火墙关了或者让防火墙忽略你的service先试试
      

  2.   

    static void Main(string[] args)
            {
                Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/ServiceModelSamples");
                ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);
    ........................http://localhost:8000/ServiceModelSamples/ServiceModelSamples
    服务在本机的时候这是对的,但是服务已经是另一台机器了,这个地址应该要改为:http://这台电脑的IP/ServiceModelSamples/ServiceModelSamples
      

  3.   

    回ls  ip地址 我已经做了相应修改,可结果还是如此。谢谢
      

  4.   

    ls的ls,我如果用socket在这2台电脑之间接发消息 ,是没问题的。但我不知道 防火墙是否能挡住wcf的消息发送?