一个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>
该如何解决? 谢谢服务器端代码: 服务器端只有契约,没配置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>
解决方案 »
- 有没有.net的工作流开源项目啊?
- 【急】.net中 根据手机号获取归属地
- 根据文件下载的地址直接下载的困惑 求助
- asp.net与javascript动态生成“层”菜单载入框架网页下拉菜单被阻挡!!!!!!!(100分)
- 急!!!如何改变Web页面上出现的滚动条的颜色???
- 在线的高手门帮帮偶啊~我有语句中有几个:select(count 1,sum a)... ,select(count 2,sum b)...,selcet(count3,sum c)...然后我要返回一
- 请各位大侠给出学习建议,谢谢
- 如何获取pannel.Controls.count的正确数量
- confirm的问题,,,高手指点。。。在先等。。急。
- 请问icyer,mbm,.net高手:在javascript与vb中怎样进行交互?
- 一个搜索的难题
- web service 如何序列化json
{
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